示例代码:
public static void main(String[] args) {
Connection conn = null;
try {
//获取连接
conn = C3p0ConnPool.getConnection();
// conn.setAutoCommit(false);
String sql = "insert into tb_User(id,name) values(?,?) ";
PreparedStatement ps = conn.prepareStatement(sql);
for (int i = 0; i < 1000; i++) {
ps.setInt(1, i);
ps.setString(2, "" + i);
ps.addBatch();
}
ps.executeBatch();
// conn.commit();
// conn.setAutoCommit(true);
} catch (Exception e) {
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
注:获取连接请参加本站JDBC、DBCP、C3P0三种方式文章
如果给你带来帮助,欢迎微信或支付宝扫一扫,赞一下。