Re: JDBC Question: Getting data from tables with columns that have the same name
- From: Thomas Kellerer <WVIJEVPANEHT@xxxxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 17:06:40 +0200
On 30.06.2005 16:54 lennyw@xxxxxxxxx wrote:
> Thanks for the advice. I'm a datacomm / realtime / C/C++/assembly
> programmer and just learning SQL, Java, eclipse and SWT
> all(unfortuately) at the same time. To me "String st1 = new String()"
> declares a reference variable, allocates a String object on the heap
> and assigns the reference to that object. And st1 =
> rs.getString("a_shortcode") makes use of the String object at the
> reference. In java do those two lines actually allocate, delete and
> reallocate the String "st1" ?
st1 is *not* a String. It is a reference to String object.
String st1 = new String();
st1 = rs.getString("a");
will create two string objects. The first one beeing immediately disposed again
when the st1 reference is pointing to the reference returned by the getString()
method (which eventually did a new String() somewhere)
Take the time to read up on the difference between objects and object
references. This will help you a lot (especially when you discover the first
time that st1 == st2 does not work even :)
"Thinking in Java" is a good starting point:
http://jamesthornton.com/eckel/TIJ-3rd-edition4.0/TIJ3.htm
Reading the language specification won't harm either
http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html#48440
Thomas
.
- References:
- Prev by Date: Re: JDBC Question: Getting data from tables with columns that have the same name
- Previous by thread: Re: JDBC Question: Getting data from tables with columns that have the same name
- Next by thread: Specify database name after connecting to Informix db via JDBC
- Index(es):
Relevant Pages
|
|