Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

db , java , mysql India
  • 13 years ago
    Hi friends .

    I was executing a query on large data in database. then i found java heap space error and it could not execute query.
    i'm giving the code below..
    I want to execute the query in batch to select the data..if suggest if there is any other way.

    ResultSet rs=null;
            Connection conn = null;
            Statement stmt = null;
                try
                 {
                     System.out.println("Database Driver loading .");
                     Class.forName("com.mysql.jdbc.Driver");
                     System.out.println("Connecting to server...");
                     try{
                        conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase","user","pwd");
                     }
                     catch(Exception e)
                     {
                        System.out.println("Database connection failed !");
                     }
                     System.out.println("Server connected.");
                     stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE,
                               ResultSet.HOLD_CURSORS_OVER_COMMIT);
                      //int fetchSize = stmt.getFetchSize();
                     stmt.setFetchSize(50);
                     //stmt.setMaxRows(500000);
                     System.out.println("Executing query.....");
                     rs=stmt.executeQuery("Select * from table");
                      //rs.setFetchSize(50);

                 }
                 catch(SQLServerException SQLEx)
                  {
                     System.out.println(SQLEx.getMessage());
                  }
                  catch(Exception Ex)
                  {
                     System.out.println(Ex.getMessage());
                  }
                 System.out.println("Query Execute Sucessfully...");


































    the error was

    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
            at java.util.Arrays.copyOf(Arrays.java:2760)
            at java.util.Arrays.copyOf(Arrays.java:2734)
            at java.util.ArrayList.ensureCapacity(ArrayList.java:167)
            at java.util.ArrayList.add(ArrayList.java:351)
            at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2306)
            at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:423)
            at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:1991)
            at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1413)
            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1757)
            at com.mysql.jdbc.Connection.execSQL(Connection.java:2998)
            at com.mysql.jdbc.Connection.execSQL(Connection.java:2927)
            at com.mysql.jdbc.Statement.executeQuery(Statement.java:956)












    I need help to solve my query execution problem on large data.
    I'm working on Windows. I set the ANT_OPTS=-Xmx512M in System Variable.
    Thanks.
    Ashwani














  • 13 years ago
  • 12 years ago

    Thanks..

    it was really very helping one

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In order to understand recursion, one must first understand recursion.”