ResultSet with more than 5 rows causes error
От | Ludovico Bianchini |
---|---|
Тема | ResultSet with more than 5 rows causes error |
Дата | |
Msg-id | 520533.88896.qm@web31903.mail.mud.yahoo.com обсуждение исходный текст |
Ответы |
Re: ResultSet with more than 5 rows causes error
|
Список | 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
В списке pgsql-jdbc по дате отправления: