Skip site navigation (1) Skip section navigation (2)

Re: Exception in thread "main" java.lang.OutOfMemoryError

From: "s anwar" <sanwar(at)gmail(dot)com>
To: rkut(at)intelerad(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Exception in thread "main" java.lang.OutOfMemoryError
Date: 2006-03-16 17:38:54
Message-ID: 3e3c86f90603160938n4fa79d5eu148a6ccc4874b11a@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
I don't think that your JDBC driver does not honor the fetch-size.
See: http://jdbc.postgresql.org/todo.html

On 3/13/06, Richard Kut <rkut(at)intelerad(dot)com> wrote:
>
> 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(at)intelerad(dot)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.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
>        message can get through to the mailing list cleanly
>

In response to

pgsql-novice by date

Next:From: s anwarDate: 2006-03-16 19:41:12
Subject: Performance of plpgsql functions
Previous:From: george youngDate: 2006-03-16 01:52:07
Subject: Re: Copying a column from one table to another

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group