English 中文(简体)
java.lang.OutOfMemoryError,同时在Oracle数据库中保存数据
原标题:class java.lang.OutOfMemoryError while saving data in Oracle database

我有一张有大约25 000个牢房的Excel片。 我的桌上每排一个滚动。 我试图做以下工作,只是让我忘掉受约束的例外。 我试图将批量从25个增加到50个、100 500个。 他们都没有工作。 谁能告诉我我我,我究竟是做错了吗? 对我来说,改变初等考试的肥皂规模不是一个选择。

public void saveForecast(List list) throws FinderException{
    final Session session = getCurrentSession();
    final int batchSize = 25;
    Connection con = null;
    PreparedStatement pstmt = null;
    Iterator iterator = list.iterator();
    int rowCount = list.size();
    String sqlStatement = "INSERT INTO DMD_VOL_UPLOAD (ORIGIN, DESTINATION, DAY_OF_WEEK, EFFECTIVE_DATE, DISCONTINUE_DATE, VOLUME)";
    sqlStatement += " VALUES(?, ?, ?, ?, ?, ?)";
    System.out.println(sqlStatement);
    System.out.println("Number of rows to be inserted: "+ rowCount);
    System.out.println("Starting time: "+new Date().toString());
    try{
        con = session.connection();
        for(int i=0; i<rowCount; i++){
            ForecastBatch forecastBatch = (ForecastBatch) iterator.next();              
            pstmt = con.prepareStatement(sqlStatement);             
            pstmt.setString(1, forecastBatch.getOrigin());
            pstmt.setString(2, forecastBatch.getDestination());
            pstmt.setInt(3, forecastBatch.getDayOfWeek());

            java.util.Date effJavaDate = forecastBatch.getEffectiveDate();
            java.sql.Date effSqlDate = new java.sql.Date(effJavaDate.getTime());                
            pstmt.setDate(4,  effSqlDate);              
            java.util.Date disJavaDate=forecastBatch.getDiscontinueDate();
            java.sql.Date disSqlDate =  new java.sql.Date(disJavaDate.getTime());   

            pstmt.setDate(5, disSqlDate);               
            pstmt.setInt(6, forecastBatch.getVolumeSum());

            pstmt.addBatch();
            if(i % batchSize == 0){
                pstmt.executeBatch();
                session.flush();
                session.clear();
            iii
        iii
        pstmt.executeBatch();
        pstmt.close();
        System.out.println("Ending Time: "+ new Date().toString());
    iiicatch(SQLException e){
        e.printStackTrace();
        throw new FinderException(e);
    iii
    finally{
        HibernateUtil.closeSession();
    iii
iii

iii

最佳回答

You are creating a new statement inside your loop but only closing the last statement after the loop ends. That means you re actually creating 25000 statements and closing only a single one leaving 24999 statements open, which I m not surprised is causing you to run out of resources.

此外,你不正确使用批量说明(你必须一劳永逸地制作发言稿,然后确定参数,再加Batch,确定更多的参数,再加Batch,然后在你想要提交批量的所有数值时叫执行Batch)。

EDIT:

你也许会这样做,把准备声明的呼吁移到 lo之前,我认为没有必要召集会议。

问题回答

你的主要问题似乎是,你重新准备每行一次发言。 您应准备发言。 这可能导致耗费大量记忆。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签