java.sql.Statement generates java.lang.OutOfMemoryError in big tabe

From: "Hartmann, Christian (externer Mitarbeiter)" <Christian(dot)Hartmann(at)schufa(dot)de>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: java.sql.Statement generates java.lang.OutOfMemoryError in big tabe
Date: 2009-01-20 16:47:04
Message-ID: 52B98DCE50D0FE4E92206EC360D324EF34FF83@SWI4201.schufa.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello all

I have a funny problem.

I have a database with two lage tables 1'900'000 and 2'800'000 records.

No I would like to open a simple courser like

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class GenerateNamenSkalierung {

/**
* @param args
* void
*/
public static void main(String[] args) {
String serverName = "servername";
String databaseName = "namenskompass20090119";
String userid = "ms_namenskompass";
String password = "";
String generalTableNamePart = "nachname";

// jdbc:db2://automatix02:52810/INSchufa
String conString = "jdbc:postgresql://" + serverName +
":5432/" + databaseName;

//userid = "ms_namenskarte";
//password = null;
String jdbcDriverName = "org.postgresql.Driver";

// SELECT id, identifier, anzahl, median FROM
public.vorname
final String sqlString1 = "SELECT id, identifier,
anzahl, median FROM public." + generalTableNamePart;

Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName(jdbcDriverName);
con = DriverManager.getConnection(conString, userid,
password);
stmt = con.createStatement();
rs = stmt.executeQuery(sqlString1);
while (rs.next()) {
//System.out.println("The Java way, res is: " +
rs.getObject(1) );
}
}catch(SQLException e){
//errorHelp(databaseName, userid, password, "");
e.printStackTrace();
}catch(ClassNotFoundException e){
//errorHelp(databaseName, userid, password, "");
e.printStackTrace();
}finally{
try{rs.close();}catch(Exception e){}
try{stmt.close();}catch(Exception e){}
try{con.close();}catch(Exception e){}
}

}

}

To iterate over all records and do some other sings.

But this simple class generates the following error.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredField(Class.java:1880)
at
java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceF
ieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:181)
at
java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(Atomi
cReferenceFieldUpdater.java:65)
at java.sql.SQLException.<clinit>(SQLException.java:353)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImp
l.java:1325)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
194)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Stateme
nt.java:451)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdb
c2Statement.java:336)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2St
atement.java:235)
at GenerateNamenSkalierung.main(GenerateNamenSkalierung.java:46)

Could this be a error in the JDBC dirver implementation?

Thanks for our help.

Greetings Chris

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2009-01-20 18:27:52 Re: java.sql.Statement generates java.lang.OutOfMemoryError in big tabe
Previous Message Dave Cramer 2009-01-20 15:56:50 Re: experience sharing: select query returns more records than necessary