javaQQ
January 23rd, 2003, 02:40 PM
How do I load the contents of a JDBC ResultSet into a Vector of Vectors?
This approach returns an error message:
theStmt = con.createStatement();
ResultSet tQ = theStmt.executeQuery( theQuery );
Vector theDataVector = new Vector();
Vector theRowVector;
while ( tQ.next() ) {
theRowVector = new Vector();
theRowVector.setElementAt( ricq.getString( "field1" ), 0 ); // field1
theRowVector.setElementAt( ricq.getString( "field2" ), 1 ); // field2
theRowVector.setElementAt( ricq.getString( "field3" ), 2 ); // field3
...
theRowVector.setElementAt( ricq.getString( "fieldX" ), 10 ); // fieldX
theDataVector.addElement( theRowVector );
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.setElementAt(Vector.java:482)
at ReaderJobUPDATE_PS_2.main(ReaderJobUPDATE_PS_2.java:531)
This code returns another error message:
theStmt = con.createStatement();
ResultSet tQ = riConfirmStmt.executeQuery( theQuery );
while ( tQ.next() ) {
for( int i = 0; i < 20; i++ ) {
for( int j = 0; j < 11; j++ ) {
((Vector)theDataVector.elementAt(i)).setElementAt( tQ.getString(i), j ); // pop_id
}
}
}
//SQLException: Column Index out of range ( 0 > 11).
//Transaction is being rolled back
//SQLException: Can't call commit when autocommit=true
What do "0 >= 0" and especially "0 > 11" (!!) refer to, and how do I fix them?
Many thanks in advance.
This approach returns an error message:
theStmt = con.createStatement();
ResultSet tQ = theStmt.executeQuery( theQuery );
Vector theDataVector = new Vector();
Vector theRowVector;
while ( tQ.next() ) {
theRowVector = new Vector();
theRowVector.setElementAt( ricq.getString( "field1" ), 0 ); // field1
theRowVector.setElementAt( ricq.getString( "field2" ), 1 ); // field2
theRowVector.setElementAt( ricq.getString( "field3" ), 2 ); // field3
...
theRowVector.setElementAt( ricq.getString( "fieldX" ), 10 ); // fieldX
theDataVector.addElement( theRowVector );
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.setElementAt(Vector.java:482)
at ReaderJobUPDATE_PS_2.main(ReaderJobUPDATE_PS_2.java:531)
This code returns another error message:
theStmt = con.createStatement();
ResultSet tQ = riConfirmStmt.executeQuery( theQuery );
while ( tQ.next() ) {
for( int i = 0; i < 20; i++ ) {
for( int j = 0; j < 11; j++ ) {
((Vector)theDataVector.elementAt(i)).setElementAt( tQ.getString(i), j ); // pop_id
}
}
}
//SQLException: Column Index out of range ( 0 > 11).
//Transaction is being rolled back
//SQLException: Can't call commit when autocommit=true
What do "0 >= 0" and especially "0 > 11" (!!) refer to, and how do I fix them?
Many thanks in advance.