pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
exception while upgrading driver
5+ messages / 3 participants
[nested] [flat]

* exception while upgrading driver
@ 2005-06-07 18:41 Sathyajith G <sathyajith@inbox.com>
  2005-06-07 19:15 ` Re: exception while upgrading driver Kris Jurka <books@ejurka.com>
  2005-06-07 21:43 ` Re: exception while upgrading driver Oliver Jowett <oliver@opencloud.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Sathyajith G @ 2005-06-07 18:41 UTC (permalink / raw)
  To: pgsql-jdbc

Hi
   i have the following code running without any errors with postgres 7.4.2.
driver.



String qry="select MAX(num) from (select
to_number((substr(acr_id,4)),'9999') as num from aircraft where acr_id  like
'ACR%'  group by acr_id) as num ";  // order by num desc";

try{
  ResultSet rs=Data.getResultSet(qry);
  while(rs.next())
   {
        try{
            acrmax=Integer.parseInt(rs.getString(1))+1;
           }catch(NumberFormatException ne){acrmax=0;}
   }
  }
  catch(SQLException ex) { System.err.println("for rs1 err
"+ex.getMessage());
        }



I changed the driver to postgres 8.0.1.  Strangely now, the above code gives
the exception "The resultset is closed". Please help.

regards,

Sathya


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: exception while upgrading driver
  2005-06-07 18:41 exception while upgrading driver Sathyajith G <sathyajith@inbox.com>
@ 2005-06-07 19:15 ` Kris Jurka <books@ejurka.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Kris Jurka @ 2005-06-07 19:15 UTC (permalink / raw)
  To: Sathyajith G <sathyajith@inbox.com>; +Cc: pgsql-jdbc



On Tue, 7 Jun 2005, Sathyajith G wrote:

>    i have the following code running without any errors with postgres 7.4.2.
> driver.
> 
> String qry="select ...;
> 
> try{
>   ResultSet rs=Data.getResultSet(qry);
>   while(rs.next())
> 
> I changed the driver to postgres 8.0.1.  Strangely now, the above code gives
> the exception "The resultset is closed". Please help.
> 

I suspect your Data.getResultSet() method looks something like this:


Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
stmt.close();
return rs;

This is not a legal thing to do, closing the Statement also closes the 
ResultSet that was created by it.  The 7.4 driver did not correctly check 
this, but the 8.0 version does.  You most postpone the Statement close 
until you are done with the ResultSet.

Kris Jurka



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: exception while upgrading driver
  2005-06-07 18:41 exception while upgrading driver Sathyajith G <sathyajith@inbox.com>
@ 2005-06-07 21:43 ` Oliver Jowett <oliver@opencloud.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Oliver Jowett @ 2005-06-07 21:43 UTC (permalink / raw)
  To: Sathyajith G <sathyajith@inbox.com>; +Cc: pgsql-jdbc

Sathyajith G wrote:

>   ResultSet rs=Data.getResultSet(qry);

> I changed the driver to postgres 8.0.1.  Strangely now, the above code gives
> the exception "The resultset is closed". Please help.

Perhapse Data.getResultSet() closes the Statement used to execute the
query before returning -- closing the Statement also closes the ResultSet.

It's hard to diagnose further without seeing all the code that's running.

-O



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: exception while upgrading driver
@ 2005-06-07 20:05 Sathyajith G <sathyajith@inbox.com>
  2005-06-07 21:46 ` Re: exception while upgrading driver Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Sathyajith G @ 2005-06-07 20:05 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

>>
>
> On Tue, 7 Jun 2005, Sathyajith G wrote:
>
> >    i have the following code running without any errors with postgres
> 7.4.2.
> > driver.
> >
> > String qry="select ...;
> >
> > try{
> >   ResultSet rs=Data.getResultSet(qry);
> >   while(rs.next())
> >
> > I changed the driver to postgres 8.0.1.  Strangely now, the above code
> gives
> > the exception "The resultset is closed". Please help.
> >
>
> I suspect your Data.getResultSet() method looks something like this:
>
>
> Statement stmt = conn.createStatement();
> ResultSet rs = stmt.executeQuery(sql);
> stmt.close();
> return rs;
>
> This is not a legal thing to do, closing the Statement also closes the
> ResultSet that was created by it.  The 7.4 driver did not correctly check
> this, but the 8.0 version does.  You most postpone the Statement close
> until you are done with the ResultSet.
>
> Kris Jurka
>

-------------------------------------------------------------------

i am not closing the statement anywhere. this is how Data.getResultSet()
looks like:

public static  ResultSet getResultSet(String sql)
     {
       ResultSet rs;
        try{
             rs=stmt.executeQuery(sql);
            }catch(Exception e)
                   {System.err.println("error");
                    rs=null;
                    }
            return rs;
     }


Sathyajith Gopi


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: exception while upgrading driver
  2005-06-07 20:05 Re: exception while upgrading driver Sathyajith G <sathyajith@inbox.com>
@ 2005-06-07 21:46 ` Oliver Jowett <oliver@opencloud.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Oliver Jowett @ 2005-06-07 21:46 UTC (permalink / raw)
  To: Sathyajith G <sathyajith@inbox.com>; +Cc: Kris Jurka <books@ejurka.com>; pgsql-jdbc

Sathyajith G wrote:

> public static  ResultSet getResultSet(String sql)
>      {
>        ResultSet rs;
>         try{
>              rs=stmt.executeQuery(sql);
>             }catch(Exception e)
>                    {System.err.println("error");
>                     rs=null;
>                     }
>             return rs;
>      }

Where does 'stmt' come from?

Can we see a compilable testcase that shows the problem? Code fragments
really aren't too useful for this sort of problem -- we need to see
everything involved with talking to the JDBC driver. e.g. perhaps the
lifetime of your Statement is not what you think it is and it's getting
GCed unexpectedly.. but I can't say for sure without seeing the actual
code you're running.

-O



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2005-06-07 21:46 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-07 18:41 exception while upgrading driver Sathyajith G <sathyajith@inbox.com>
2005-06-07 19:15 ` Kris Jurka <books@ejurka.com>
2005-06-07 21:43 ` Oliver Jowett <oliver@opencloud.com>
2005-06-07 20:05 Re: exception while upgrading driver Sathyajith G <sathyajith@inbox.com>
2005-06-07 21:46 ` Oliver Jowett <oliver@opencloud.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox