jdbc批量插入数据

以下过程网上看到,备份一下语法而已
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
String sql = "insert into user(name,birthday, money) values (?, ?, ?) ";
ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
for (int i = 0; i < 100; i++) {
ps.setString(1, "batch name" + i);
ps.setDate(2, new Date(System.currentTimeMillis()));
ps.setFloat(3, 100f + i);

ps.addBatch();
}
int[] is = ps.executeBatch();
} finally {
JdbcUtils.free(rs, ps, conn);
}

你可能感兴趣的:(jdbc)