Exception in thread "main" java.lang.OutOfMemoryError - Mailing list pgsql-novice
From | Richard Kut |
---|---|
Subject | Exception in thread "main" java.lang.OutOfMemoryError |
Date | |
Msg-id | 200603131339.11880.rkut@intelerad.com Whole thread Raw |
Responses |
Re: Exception in thread "main" java.lang.OutOfMemoryError
Re: Exception in thread "main" java.lang.OutOfMemoryError |
List | pgsql-novice |
Hello! I am trying to use a cursor in Java to fetch multiple rows at once. The code seems to connect to the database okay, and seems to be fetching records, but then it fails with the error: Exception in thread "main" java.lang.OutOfMemoryError Here is the Java code: import java.sql.*; /* * To compile: * * /usr/bin/jikes -source 1.4 -bootclasspath /usr/java/j2sdk1.4.2_02/jre/lib/rt.jar:/usr/java/j2sdk1.4.2_02/jre/lib/jsse.jar:/usr/java/j2sdk1.4.2_02/jre/li b/jce.jar test_connect.java * * * To run: * * java -cp /usr/share/java/postgresql-8.1-404.jdbc2.jar:/usr/java/j2sdk1.4.2_02/jre/lib/rt.jar:/usr/java/j2sdk1.4.2_02/jre/lib/jsse.jar:/usr/java/j2sdk1.4. 2_02/jre/lib/jce.jar:. test_connect */ class test_connect { private static Connection connectToDb( String dbName, String username, String password ) throws Exception { System.out.println( "Connecting to DB " + dbName + ", username " + username ); String dbDriver = "org.postgresql.Driver"; String url = "jdbc:postgresql://imsstd4/" + dbName; Class.forName( dbDriver ).newInstance(); System.out.println( "Connecting to " + url + " with user " + username + " and pass " + password ); Connection connection = DriverManager.getConnection( url, username, password ); System.out.println( "Connection successful" ); return connection; } private static void executeQuery( Connection connection ) throws SQLException { String sql = "SELECT * FROM pid, pv1 where pid.patient_id_internal_id = pv1.patient_id_internal_id"; System.out.println( "Executing query: " + sql ); Statement st = connection.createStatement(); System.out.println( "Setting cursor size to 50 rows." ); st.setFetchSize( 50 ); // turn on cursor ResultSet rs = st.executeQuery( sql ); System.out.println( "Got 50 results. Now walking them..." ); int i = 0; while ( rs.next() ) { // Do not print anything here for now i++; System.out.println( "Row " + i ); } System.out.println( "Result set consumed " + i + " rows." ); } public static void main( String[] args ) { System.out.println( "Starting up..." ); try { Connection connection = connectToDb( "hl7segmentsihe", "hl7", "segments" ); executeQuery( connection ); } catch ( Exception e ) { System.out.println( "Got exception " + e ); e.printStackTrace(); } } } Here is the program output: Starting up... Connecting to DB hl7segmentsihe, username hl7 Connecting to jdbc:postgresql://imsstd4/hl7segmentsihe with user hl7 and pass segments Connection successful Executing query: SELECT * FROM pid, pv1 where pid.patient_id_internal_id = pv1.patient_id_internal_id Setting cursor size to 50 rows. Exception in thread "main" java.lang.OutOfMemoryError What did I do wrong? Any help would be appreciated. -- Regards, Richard Kut Database Administrator Research & Development Intelerad Medical Systems Inc. 460 Ste-Catherine West, Suite 210 Montreal, Quebec, Canada H3B 1A7 Tel: 514.931.6222 x7733 Fax: 514.931.4653 rkut@intelerad.com www.intelerad.com This email or any attachments may contain confidential or legally privileged information intended for the sole use of the addressees. Any use, redistribution, disclosure, or reproduction of this information, except as intended, is prohibited. If you received this email in error, please notify the sender and remove all copies of the message, including any attachments.
pgsql-novice by date: