JDBC_Batch

错误代码:
pStmt = conn.prepareStatement("insert into dept2 values (?,?,?)");

pStmt.setInt(1, 58);
pStmt.setString(2, "500");
pStmt.setString(3, "haha");
pStmt.executeBatch();

pStmt.setInt(1, 59);
pStmt.setString(2, "500");
pStmt.setString(3, "haha");
pStmt.executeBatch();

...

查看数据库无更新

分析:语句没执行,没有向Batch中添加sql语句,就执行Batch

解决:
pStmt.setInt(1, 58);
pStmt.setString(2, "500");
pStmt.setString(3, "haha");
//添加sql语句到Batch中
pStmt.addBatch();
pStmt.executeBatch();

你可能感兴趣的:(java,sql,jdbc)