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



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
.



Relevant Pages

  • Re: C# Fundamentals Part 3: ReferenceEquals question
    ... |> take a look at the remark clausein the Framework reference guide. ... What is an "Empty ... String.Empty is a public static field of type String initialized ... empty string object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: After deserialization program occupies about 66% more RAM
    ... by the string object. ... "interned reference" is probably a bit better. ... When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equalsmethod, then the string from the pool is returned. ...
    (comp.lang.java.programmer)
  • Re: Function Declaration
    ... | If I pass a structure byval that contains both reference and value types, ... single copy of the String object on the heap. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: programming concepts > specific languages
    ... >> On the second line, the value of the reference is passed along, not the ... >the string, and performs a therefore useless manipulation of it. ... Immutability of objects is, AFAIK, implemented simply by not providing ... myString *which is a reference to a String object*, ...
    (comp.programming)
  • Re: Complex Specified Information - Pitman Formula
    ... Therefore a significant match between a reference and a test ... string is good evidence of non-random production. ... and there are no finite algorithms to compute their digits. ... probabilities of the different symbols the information source can produce. ...
    (talk.origins)