关于PreparedStatament的大批量插入数据库的写法

这样写有问题吗!
为什么到最后只执行了一条sql语句
是不是应该该成用 Statement 来代替 PreparedStatement呀
public boolean execInsertTables(String[] sqls) {

		boolean flag = false;
		con = dbc.getConnection();
		try {
			con.setAutoCommit(false);
			int a = 0;
			for (int i = 0; i < sqls.length; i++) {
				pst = con.prepareStatement(sqls[i]);
				pst.addBatch();
				if(i<sqls.length-1){
					pst.close();
				}
				a = i;
			}
			System.out.println(a+" ** "+sqls.length);
			pst.executeBatch();
			con.commit();
			flag = true;
		} catch (Exception e) {
			flag = false;
			Tasklogger.debug("插入数据失败 TaskDao 里的 execInsertTables!" + e);
			e.printStackTrace();
		} finally {
			dbc.closeExe(pst, con);
		}
		return flag;
	}

你可能感兴趣的:(sql)