5 回答
TA贡献1825条经验 获得超6个赞
[i]stmt_Select.close(); [/i] stmt_Select=con.createStatement(); [i] stmt_Update.close();[/i] stmt_Update=con.createStatement();
不要在循环里面频繁的close, 全部放在rs.close()之前
参考如下
stmt_Select.close();
stmt_Update.close();
rs.close();
TA贡献1820条经验 获得超9个赞
PreparedStatement[quote] PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, 153833.00)
pstmt.setInt(2, 110592)
[/quote]
TA贡献1836条经验 获得超3个赞
建议你使用Updatable statement,给你一段我以前写过的代码吧,这段代码用来处理14万条记录,具体时间记不太清了,不过效率还是挺高的:
[code="java"]
String sql = "select ccrq,dt_factory_date from ajdq";
Connection con = DbUtil._CONNECTION;//获得数据库连接
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery(sql);
int i=0;
while(rs.next()){
String date = rs.getString(1);
Date d = DateUtil.parse(date);
if(d!=null){
rs.updateTimestamp(2, new Timestamp(d.getTime()));
rs.updateRow();
i++;
System.out.print(".");
if(i%100==0){
System.out.println(i);
con.commit();
}
}
}
rs.close();
st.close();
System.out.println();
System.out.println(i);
con.commit();
con.close();
[/code]
添加回答
举报