pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ludovico Bianchini <metlud@yahoo.it>
To: pgsql-jdbc@postgresql.org
Subject: ResultSet with more than 5 rows causes error
Date: Thu, 27 Sep 2007 12:20:10 +0200 (CEST)
Message-ID: <520533.88896.qm@web31903.mail.mud.yahoo.com> (raw)

I'm using jdbc4 driver with postgresql 8.1, java sdk 6
and netbeans 5.5
The task to perform is to copy rows from one table to
another (tables with same structure) in a distinct
database, using stored procedure.
This code works fine when the ResultSet has max 5
rows. If it has 6 rows, when calling getObject(int
index) an error occurs.
The error seems to be PSQLException, telling that the
ResultSet is bad positioned and an hit could be
calling next(). But it's not
clear: what I have caught is a NullPointerException


public void upload(Connection localConnection,
Connection remoteConnection) throws SQLException{ 



ResultSet source; 
ResultSetMetaData md; 
SQLWarning warning; 
Object data; 
int colCount; 
try { 
if (localConnection != null && remoteConnection !=
null && !localConnection.isClosed() &&
!remoteConnection.isClosed()) { 
remoteConnection.setAutoCommit(false); 
CallableStatement selectCall =
localConnection.prepareCall(Constant.FUNCTION_SELECT);

CallableStatement insertCall =
remoteConnection.prepareCall(Constant.FUNCTION_INSERT);

source = selectCall.executeQuery(); 
md = source.getMetaData(); 
colCount = md.getColumnCount(); 
while(source.next()) { 
insertCall.registerOutParameter(1, Types.INTEGER); 
for (int i = 1; i <= colCount; i++) { 
data = source.getObject(i); 
insertCall.setObject(i+1, data); 
} 
insertCall.execute(); 
warning = insertCall.getWarnings(); 
insertCall.clearParameters(); 
} 
source.close(); 
selectCall.close(); 
insertCall.close(); 
remoteConnection.commit(); 
remoteConnection.close(); 
} 
} catch (PSQLException ex) { 
remoteConnection.rollback(); 
remoteConnection.close(); 
} 
catch (SQLException ex) { 
remoteConnection.rollback(); 
remoteConnection.close(); 
} 
catch (Exception ex) { 
remoteConnection.rollback(); 
remoteConnection.close(); 
}

}

Abybody can help me to find an answer?

Thanks in advance 


      ___________________________________ 
L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail: http://it.docs.yahoo.com/nowyoucan.html



view thread (11+ messages)  latest in thread

Message-ID: <520533.88896.qm@web31903.mail.mud.yahoo.com>
Permalink:  ../520533.88896.qm@web31903.mail.mud.yahoo.com/
Also on:    postgresql.org/message-id/520533.88896.qm@web31903.mail.mud.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: metlud@yahoo.it
  Subject: Re: ResultSet with more than 5 rows causes error
  In-Reply-To: <520533.88896.qm@web31903.mail.mud.yahoo.com>
  References: <520533.88896.qm@web31903.mail.mud.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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