Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Referencing table-aliased column names in JDBC

306784Jul 12 2002
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 9 2002
Added on Jul 12 2002
0 comments
612 views