aspose file tools*
The moose likes JDBC and the fly likes out of memory error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "out of memory error" Watch "out of memory error" New topic

out of memory error

Pinik Tilli

Joined: Jul 19, 2006
Posts: 19

I would be glad if someone could provide me any solution for this error.
I am trying to execute the SQL query for the table which consists of morethan 2 millions of rows. And i am using CachedRowSetImpl()to populate the resultset and use this object later for retreiving the details. But when i am trying to populate outofmemory error is obtained.

Any other suggestions are acceptable.

working Env:
jdeveloper 10g for development
oracle 10g for database

Below is the code:

public boolean getDataFromDB(Connection conn, String sqlQuery,
Map parameters) throws CDaoException {

PreparedStatement prepStmt = null;
ResultSet rs = null;
StringBuffer sql = new StringBuffer();
String value = null;
int a =0;

try {

prepStmt = conn.prepareStatement(sql.toString());

if( parameters != null ){
// set the parameters for query
for( int i=0 ; i < parameters.size() ; i++){
a = i+1;
if( parameters.containsKey(a) ){
value = (String)parameters.get(a);

rs = prepStmt.executeQuery();

crs = new CachedRowSetImpl();
crs.populate(rs); // Error is obtained at this statement.

return true;

} catch (SQLException e) {
throw new CDaoException("\n Error preparing SQL statement: " + sqlQuery + " \n Please enter the correct SQL statement");
} // end public boolean getDataFromDB(Connection conn, String sqlQuery,Set parameters) */

Thanks once again.
Joshy Thomas

Joined: Jul 23, 2004
Posts: 13
What is your query like ? Are you getting all 2 million records in one query ?.

<a href="" target="_blank" rel="nofollow">Free Tax Software</a>
Pinik Tilli

Joined: Jul 19, 2006
Posts: 19
The SQL Query is select * from DP_MASTER_ACTIVE.
when this query is executed i get morethan 2million of records.
Please provide the solution.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18986

There are two approaches to this:

1. Provide the JVM with enough memory to store all two million records.

2. Redesign your application so that you don't have to have all two million records in memory at once.

If #1 is impossible then you will have to use #2.

(I don't know what environment this code is running in so it's hard to say how to provide more memory.)
seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 59
Pinik Tilli
You can use setPage to the CacheRowSetImpl to set the number of rows to include at a particular time.So you should not fine with that out of memory thing for now.
Serkan Demir
Ranch Hand

Joined: Feb 03, 2005
Posts: 61
Hi Pinni,
May i learn your starting heap size?

A guy from Turkey<br /><a href="" target="_blank" rel="nofollow"></a>
Pinik Tilli

Joined: Jul 19, 2006
Posts: 19

Thanks for all valuable suggestions.

Coming to heap size , both max and min is set to 512M.
MaxPermSize is set to 160M.
I agree. Here's the link:
subject: out of memory error