通过PreparedStatement批量执行sql语句【sql语句相同,值不同】
2015-07-17 14:11
323 查看
比如说:我有一个List需要添加到数据库中,那么我该如何通过PreparedStatement来操作呢?
阅读更多
public void addCustomerByCommit(Connection conn , List<Customer> customerList)
{
String sql = "inseret into customer(id , name , remark)values(?,?,?)";
try
{
PreparedStatement ps = conn.prepareStatement(sql);
for(Customer customer :customerList){
int index = 1;
ps.setInt(index++ , customer.getId())
ps.setString(index++, customer.getName());
ps.setString(index++, customer.getRemark());
ps.addBatch();
}
ps.executeBatch();
}
catch (SQLException e)
{
//这里呢你可以做点自己想做的事情
e.printStackTrace();
}
}
相关文章推荐
- mysql通过sql语句如何批量去掉某一个表中某一个字段的下面的相同部分字符串
- 在Oracle中不通过存储过程一次执行多条SQL语句Oracle PL/SQL
- 通过脚本执行sql语句
- 奇怪!同一条sql语句在数据库和代码中执行结果不同?!当然是人错了 ……
- BOS客户端不通过服务端去执行sql语句
- 《DB 查询分析器》批量执行多条SQL语句并查看各自的执行时间
- Mybatis之批量执行SQL语句
- java批量执行多条Sql语句
- 通过分析SQL语句的执行计划优化SQL(三)
- 关于mysql 执行批量的sql 语句问题:&allowMultiQueries=true
- c#实现用SQL池(多线程),批量执行SQL语句
- PL/SQL中批量执行SQL脚本(不可把所有的语句都复制到New SQL Windows)
- 通过分析SQL语句的执行计划优化SQL (四)
- 通过分析SQL语句的执行计划优化SQL语句(一)
- PHP mysqli 增强 批量执行sql 语句的实现代码
- 在Oracle中不通过存储过程一次执行多条SQL语句Oracle PL/SQL
- mysql通过查看跟踪日志跟踪执行的sql语句
- 如果在一个SQL语句中有两个来自不同表的字段,有相同的字段名怎么办?
- 通过Excel生成批量SQL语句,处理大量数据的好办法
- 如何通过outline为SQL语句指定执行计划