ResultSet with more than 5 rows causes error

From: Ludovico Bianchini <metlud(at)yahoo(dot)it>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: ResultSet with more than 5 rows causes error
Date: 2007-09-27 10:20:10
Message-ID: 520533.88896.qm@web31903.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Ludovico Bianchini 2007-09-27 15:54:35 Re: ResultSet with more than 5 rows causes error
Previous Message Heiko W.Rupp 2007-09-26 17:29:00 Re: Idle in Transaction ..