ResultSet getXXXX Behavior
Date: 1999/10/29
Message-ID: <ra9S3.2116$Hc.6671555_at_news.optonline.net>#1/1
We are not sure if this is the correct behavior for a result set.
public void testAlias( com.gtms.securities.SecurityMasterImpl bo )
{
String sedol;
String desc;
String ctyCode;
String currCode;
try
{
// Create and execute the SQL statement.
Statement statement = _conn.createStatement();
java.sql.ResultSet rs = statement.executeQuery
(“SELECT
sm1.sedol s, sm1.description d, sm2.ctycode c, sm2.currcode cc
FROM securitymaster sm1, securitymaster sm2 WHERE sm1.id = 89
AND sm1.id = sm2.id” );
if ( rs.next() )
{
sedol = rs.getString( “s” );
System.out.println(“********** SEDOL = “ + sedol); desc = rs.getString( “d” );
System.out.println(“********** DESCRIPTION = “ + desc); currCode = rs.getString( “cc” );
System.out.println(“********** CURRCODE = “ + currCode); ctyCode = rs.getString( “c” );
System.out.println(“********** CTYCODE = “ + ctyCode); }
statement.close();
statement = null;
}
catch( SQLException sqle )
{
System.out.println( sqle );
}
}
This is the result:
Oct 28 12:06:15 1999: ********** SEDOL = 4019950
Oct 28 12:06:15 1999: ********** DESCRIPTION = ALLGEMEINE BAUGE S TAMM AUSH
1000
Oct 28 12:06:15 1999: ********** CURRCODE = EUR
Oct 28 12:06:15 1999: java.sql.SQLException: [Oracle][ODBC]Invalid column
number <3>.
It seems that if the rs.getXXX( “whatever” ) are not in the same order as the columns in the select statement it won’t work. After experimenting it seems that once you have retrieved the value from a specific column, you can ’t go backwards. It behaves the same way if we use column index instead of column name on the getXXXX. If the columns are accessed in order, everything works.
Are we missing something or do the getXXXs need to be in the same order as the columns in order to retreive data out of the result set? Received on Fri Oct 29 1999 - 00:00:00 CEST