JDBC Question: Getting data from tables with columns that have the same name



Hi

I'm making a JDBC SQL query that looks something like this:

select <a bunch of columns>, a.shortcode, <some more coumns>,
z.shortcode from Table1 a, Table2 b, Table3 z where <join conditions>,
<more conditions>

I get reasonable values in my JDBC result set.

I've been trying to extract the two "shortcode" column data items that
came from Table1 and Table3 from my result set rows with calls like:

String st1 = new String();
String st2 = new String();
st1 = rs.getString("a.shortcode");
st2 = rs.getString("z.shortcode");

or with

st1 = rs.getString("Table1.shortcode");
st2 = rs.getString("Table3.shortcode");

All of these formulations result in a SQL Exception of field name not
recognized.

Though I haven't tried it, I'm sure I could use indexes to get at the
columns:

st1 = rs.getString(8)l
st2 = rs.getString(21);

but this would make maintenance a bit rough down the line, if/when the
query changes.

Am I doing something wrong, or does JDBC not know about table names or
table aliases in getNNN(String s) calls on result sets?

For your info, the database is Oracle 9i, the JDBC driver is in
ojdbc14.jar, which was on the computer when I inherited it, and I
presume that's what is connecting me to the database. I'm writing this
from home so I don't have access to the source code, but part of the
connection string inincludes "OCI8" in it followed by ID password and
service (don't remember the order though).

Any advice would be greatly appreciated!

-Lenny Wintfeld

.



Relevant Pages

  • Re: Access Oracle Objects via PLSQL from JDBC
    ... In oracle demos I couldn't find a such examples.... ... This example uses a JDBC thin client to call a PLSQL stored ... test.java - this calls the plsql and displays the resultset ... // JDBC Implementation specific connect string ...
    (comp.lang.java.programmer)
  • Re: JDBC Question: Getting data from tables with columns that have the same name
    ... > I'm making a JDBC SQL query that looks something like this: ... > I get reasonable values in my JDBC result set. ... > String st1 = new String; ... > query changes. ...
    (comp.lang.java.databases)
  • Re: jdbc connection to Sybase
    ... long string parameter. ... JDBC just sends the string as-is. ... PreparedStatement p = c.prepareStatement; ...
    (comp.lang.java.databases)
  • Re: how do i compare dates in JSP
    ... Use the java.text.DateFormat class to format the date String into a ... Assuming that the database date is retrieved via JDBC ... as a java.sql.Date object (whixh extends the java.util.Date class) you ...
    (comp.lang.java.help)