prepareStatement.addBatch() //添加sql进入prepareStatement中
prepareStatement.executeBath() //批量执行sql
//例子:
PreparedStatement ps = null;
public void addFlowCardDetail(String flowCardVouNo,List<FlowCardDetail> flowCardDetailList) throws DaoException {
StringBuffer sbSql = new StringBuffer();
sbSql.append("......");
try {
Connection conn = ConnectionManager.getConnection();
ps = conn.prepareStatement(sbSql.toString());
for (Iterator<FlowCardDetail> iter=flowCardDetailList.iterator(); iter.hasNext();) {
ps.setString(1, flowCardVouNo);
......
//ps.executeUpdate(); //不去多次与数据库打交道,采用下面的作法
ps.addBatch(); //PreparedStatement对象的addBatch()方法用来批量增加一组sql
}
ps.executeBatch(); //PreparedStatement对象的executeBatch()方法用来执行增加一组sql
}catch(SQLException e) {
......
}finally {
ConnectionManager.close(ps);
}
}
prepareStatement.executeBath() //批量执行sql
//例子:
PreparedStatement ps = null;
public void addFlowCardDetail(String flowCardVouNo,List<FlowCardDetail> flowCardDetailList) throws DaoException {
StringBuffer sbSql = new StringBuffer();
sbSql.append("......");
try {
Connection conn = ConnectionManager.getConnection();
ps = conn.prepareStatement(sbSql.toString());
for (Iterator<FlowCardDetail> iter=flowCardDetailList.iterator(); iter.hasNext();) {
ps.setString(1, flowCardVouNo);
......
//ps.executeUpdate(); //不去多次与数据库打交道,采用下面的作法
ps.addBatch(); //PreparedStatement对象的addBatch()方法用来批量增加一组sql
}
ps.executeBatch(); //PreparedStatement对象的executeBatch()方法用来执行增加一组sql
}catch(SQLException e) {
......
}finally {
ConnectionManager.close(ps);
}
}