JDBC批处理的API
1.Statement批处理:
void addBatch(String sql) 添加sql到缓存区(暂时不发送)
int[] executeBatch() 执行批处理命令。 发送所有缓存区的sql
void clearBatch() 清空sql缓存区
PreparedStatement批处理:
void addBatch() 添加参数到缓存区
int[] executeBatch() 执行批处理命令。 发送所有缓存区的sql
2.JDBC获取自增长值
* 1.1 使用两个参数的prepareStatement()方法,指定可以返回自动增长的键值
* Statement.RETURN_GENERATED_KEYS: 可以返回自动增长值
* Statement.NO_GENERATED_KEYS: 不能返回自动增长值
/
stmt = conn.prepareStatement(deptSql, Statement.RETURN_GENERATED_KEYS);
//设置参数
stmt.setString(1, “秘书部”);
//执行部门sql
stmt.executeUpdate();
/*
* 1.2 获取自增长的值
*/
rs = stmt.getGeneratedKeys();
Integer deptId = ;
if(rs.next()){
}