Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trying to return value in Resultset....try catch error

843840Mar 20 2008 — edited Mar 21 2008
Hi all,
Iam trying to return a value from a resultset to be used in a jsp textbox. The problem i am having is that this value is hidden within the try..catch block and can not be returned. i have tried using the "throws SQLException" statement but with no success. Please is there any other way i can achieve this?? The jsp calls this method (below) to retrieve the required value:
public String getValue1(String record) 
{
ResultSet rs = null;
String value1;
try
{
String sql = "SELECT column1 FROM myTable WHERE RecordNumber= '" + record + "'";
//
rs = theStatement.executeQuery(sql); 
while (rs.next())
{
value1 = new String(rs.getString("column1"));
return value1;// <--not working
}

}
catch (SQLException sqle) {
System.err.println("Error Retrieving record" +sqle);
}
return value1; // <----error "variable might not have been initialized"
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 18 2008
Added on Mar 20 2008
12 comments
404 views