Re: JDBC Question: Getting data from tables with columns that have the same name
- From: Lee Fesperman <firstsql@xxxxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 23:34:43 GMT
lennyw wrote:
>
> 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?
I think the JDBC spec implies that the drivers should only match on column name.
If you can't change the query to use distinct names, the only other choice is to search
the meta data (ResultSetMetaData) yourself. That's not as bad as it sounds.
--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
.
- Prev by Date: Re: RefCursor works in SQL*Plus but not JDBC
- Next by Date: mysql sql statement running in ANT
- Previous by thread: Re: RefCursor works in SQL*Plus but not JDBC
- Next by thread: mysql sql statement running in ANT
- Index(es):
Relevant Pages
|
|