各位大虾,最近小弟在做程序时碰到一个关于JDBC rs.updateRow()批量更新时的内存溢出问题,每当更新数据到30万左右时就会出现内存溢出问题,在网上查相关信息,但是问题还是没能得到解决,还望大虾们帮忙解决一下。在此小弟先谢各位了。代码如下:public void contrast(String strid){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
conn = JdbcUtil.getConnection();
conn.setAutoCommit(false);
String sql = "select ver from test_tb_reference " +" where statistics_id='"+strid+"'";
System.out.println("--"+sql);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
int i=0;
while(rs.next()){
i++;
rs.updateString(1,"一版");
rs.updateRow();
if(i%500==0){
conn.commit();
System.gc();
}
System.out.println("---"+i);
}
conn.commit();
System.out.println("commit执行完毕!");
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
}
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
System.out.println("连接关闭!");
}
}catch(Exception e2){
e2.printStackTrace();
}
}
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
conn = JdbcUtil.getConnection();
conn.setAutoCommit(false);
String sql = "select ver from test_tb_reference " +" where statistics_id='"+strid+"'";
System.out.println("--"+sql);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
int i=0;
while(rs.next()){
i++;
rs.updateString(1,"一版");
rs.updateRow();
if(i%500==0){
conn.commit();
System.gc();
}
System.out.println("---"+i);
}
conn.commit();
System.out.println("commit执行完毕!");
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
}
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
System.out.println("连接关闭!");
}
}catch(Exception e2){
e2.printStackTrace();
}
}
}
解决方案 »
- Java中类的问题,求解,谢谢
- 同一台服务器上部署两个TOMCAT
- 求sql语句 相同id的插入--------------------急!!!!!!!!!!
- 用new String(inStr.getBytes("UTF-8"),"GBK")中文标点符合乱码,请高手指点。
- 谁用过jprofiler,路径中遇到空格怎么办?
- Spring的技术重点仅仅是IoC AOP和声明式事务吗?以及SSH整合的结合点有几种?
- 求教hibernate对sqlserver的varbinary的读取问题?谢谢了
- SAX入门
- 高分求孙卫琴的《精通Struts:基于MVC的Java Web设计与开发 》配套光盘代码
- 在jboss中如何设置数据源(sybase),马上结贴!!
- 研究透这10个项目中的几个,你就是J2EE开发高级人才
- spring jdbc事务处理自身嵌套调用方法的问题!!!很难解决的问题,求真真高手解答
------------------------------------------------------