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



On 30.06.2005 03:35 lennyw wrote:
> 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");

Simply give them a column alias:

SELECT <bunch>, a.shortcode as a_shortcode, z.shortcode as z_shortcode
FROM ....

st1 = rs.getString("a_shortcode"),
st2 = rs.getString("z_shortcode");

> String st1 = new String();
> String st2 = new String();

Why do you do that? You create a new object just to throw it away in the next
line (when you assign a new value to the variable).
This is not needed.

Thomas



.



Relevant Pages

  • RE: Copy Column data to Page Header
    ... I would like assistance to write a macro which creates a page center to read ... from column data. ... I would like for example the text string to read "Wasuto ...
    (microsoft.public.excel.programming)
  • Copy Column data to Page Header
    ... I would like assistance to write a macro which creates a page center to read ... from column data. ... I would like for example the text string to read "Wasuto ...
    (microsoft.public.excel.programming)
  • Like a matrix
    ... I have a string of numbers in a file like so: ... since I'm reading one line at a time, but how can I do it vertically like 0 ... I was thinking of a dictionary but how do you add entries to a dictionary, ... which has the 0th column data. ...
    (comp.lang.python)
  • XML::Generator::DBI - use of uninitialized value on line 180 and 187
    ... module to generate xml files. ... For every column data in the database I ... Use of uninitialized value in string eq at ...
    (comp.lang.perl.misc)
  • XML::Generator::DBI - use of uninitialized value on line 180 and 187
    ... module to generate xml files. ... For every column data in the database I ... Use of uninitialized value in string eq at ...
    (comp.lang.perl.modules)