Hi Ted,

    It seems to me that even if you were right, you'd be wrong in the sense
that the compiler disagrees with you.  Remember that the compiler error was:

>> JDBCServlet.java:115: Variable rs may not have been initialized.
>>  String sd  =  rs.getString(2);

    So, is the compiler wrong?  If you look at the JLS paragraph preceeding
your 4.5.4 reference, that is, 4.5.3 Kinds of Variables, you'll see that, in
a situation like the following ( whether inside a class or not, )

public void myLocalMethod()
{
   ResultSet rs;
}

rs fits the definition of local variable.  It is not a class variable,
instance variable or array component as defined in 4.5.3.  Your own quote
states "A local variable (�14.3, �14.12) must be explicitly given a
value..."  More detail is given in 14.3.4 Execution of Local Variable
Declarations.  I'd say that Srini is dead on.



                                                    Joe Sam



Joe Sam Shirah
Autumn Software
Consulting/Development Services when YOU need them
___________________________________________

-----Original Message-----
From: Ted Neward <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Saturday, December 18, 1999 11:11 PM
Subject: Re: error messages


Srini, unfortunately, you're absolutely incorrect on this. References are
always set to null if not declared to be any other value; it's in the Java
Lang Spec:

Section 4.5.4 ("Initial Values of Variables") of the JLS:

[snip quote]
...
A local variable (�14.3, �14.12) must be explicitly given a value before it
is used, by either initialization (�14.3) or assignment (�15.25), in a way
that can be verified by the compiler using the rules for definite assignment
(�16).
...

[snip quote]


Ted Neward
Java Instructor, DevelopMentor ( http://www.develop.com )
http://www.javageeks.com/~tneward


-----Original Message-----
From: Srini <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Sunday, December 12, 1999 9:40 PM
Subject: Re: error messages


>very simple
>
>ur declaring rs as a local variable so it has to be initialized to any
value
>before ur accessing it.  Instead of
>
>ResultSet rs;
>
>say
>
>ResultSet rs=null;
>
>and put ur code in a try and catch block.
>
>Hope this Helps
>Srini
>
>Kelsey Fedde wrote:
>
>> JDBCServlet.java:115: Variable rs may not have been initialized.
>>  String sd  =  rs.getString(2);
>>                �
>> JDBCServlet.java:115: Exception java.sql.SQLException must be caught, or
it
>> must
>>  be declared in the throws clause of this method.
>>  String sd  =  rs.getString(2);
>>

...
>> suggestions?
>>
>> thanks,
>> Kelsey
>>
>>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to