JavaMysql批处理

2016-12-07  本文已影响15人  chad_it

写在前面

详细过程

Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(url, "用户名", "密码");
String sqlString = "insert into 表名(列名, 列名) values(?, ?)";
PreparedStatement preparedStatement = connection.prepareStatedment(sqlString);
preparedStatement.setString(1, String);
preparedStatement.setString(2, String);
//添加批处理
preparedStatement.addBatch();
preparedStatement.setString(1, String);
preparedStatement.setString(2, String);
//添加批处理
preparedStatement.addBatch();
//执行批处理
preparedStatement.excuteBatch();
//清空批处理
preparedStatement.clearBatch();
//关闭
connection.close();
preparedStatement.close();
上一篇下一篇

猜你喜欢

热点阅读