Referencing table-aliased column names in JDBC
We are attempting to port an application from MySQL to Oracle 8i, using JDBC as the database connection technology. The app has SQL statements using joins, e.g.
SELECT A.*, B.* FROM table1 A, table2 B WHERE A.field1=B.field2 etc
Often the tables have columns sharing the same name, so the table alias is required to avoid ambiguity (e.g. both tables have column ID, so they must be referenced as A.ID or B.ID).
When using MySQL, the Java code
String strField = rset.getString( "SURNAME" );
or
String strField = rset.getString( "A.SURNAME" );
both succeed if the column name is unique, and if it is not unique, only the second form works. However, with Oracle, the second form never works, even though the column name is a valid column in the table aliased as A. Providing the whole table name does not work either:
String strField = rset.getString( "table1.SURNAME" );
If the Oracle JDBC driver does not support the {table-alias}.{column-name} syntax, then presumably the only way to reference ambiguous columns in joins is to supply the column number instead. (e.g. getString( 14 )). Our application generates dynamic SQL, and having to do this would be a MAJOR problem.
We are currently using Oracle 8i - might this have been fixed in the move to 9i?
Many thanks for any help,
Steve Francis,
London, UK.