【发布时间】:2017-01-30 12:30:15
【问题描述】:
我正在从磁盘加载一个文件,它包含 9,00,000 条记录。我正在逐行读取文件并对其进行处理,然后将其设置为 java 对象。对于每条记录,正在执行以下代码(它将执行一个插入,一更新一选择查询)
try
{
if(conn != null)
{
selectPrepareStatement.setString(1, someValue);
selectPrepareStatement.setMaxRows(1);
rs = selectPrepareStatement.executeQuery();
String secondaryCIF = null;
insertPreparedStatement.setInt(1, vo.getRecordType());
insertPreparedStatement.setString(2, vo.getRefType());
insertPreparedStatement.setString(3, vo.getCustOwnershipType());
insertPreparedStatement.setString(4, vo.getTin());
insertPreparedStatement.setString(5, vo.getCifId());
insertPreparedStatement.setString(6, vo.getPrimaryOrSecondary());
Statement statement = conn.createStatement();
if(vo.getPrimaryOrSecondary().equals("P"))
{
updatedCount = statement.executeUpdate("update table_name set col1='"+value1+"' where col2= '"+value2)+"'");
updatedCount = statement.executeUpdate();
}else if(vo.getPrimaryOrSecondary().equals("S"))
{
updatedCount = statement.executeUpdate("update table_name set col3='"+value3+"' where CUST_CIN = '"+value1+"'");
updatedCount = statement.executeUpdate();
}
insertPreparedStatement.setInt(8, updatedCount);
insertPreparedStatement.setString(9, null);
insertPreparedStatement.executeUpdate();
}
if(rs != null)
{
rs.close();
}
}catch(Exception e)
{
}
如果我将堆空间增加到 1GB,然后在 3,00,000 条记录后出现错误。有人可以帮我解决这个问题吗?
所有准备好的语句和变量都声明为全局和静态的。
【问题讨论】:
-
看到你这样受人尊敬的高分用户提出如此糟糕的问题,我感到非常惊讶
-
这个文件有多大(MB)?您是否在每次迭代中存储任何内容?
-
好的,缺少的是那些你正在执行数据库查询的代码行,这是必不可少的
-
我尝试了很多解决方案。所以我在 SO 中发帖
-
在我看来,您将所有读取的数据都保存在内存中。但是如果没有更多的代码,我们很难准确地定义在哪里。可能是您准备好的语句代码或 TINDetailsVO 或 ...
标签: java file out-of-memory heap-memory