Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Missing a Finally but I don't want a finally

Status
Not open for further replies.

faiyth

Programmer
Nov 22, 2002
19
US
I keep getting an error.. I've been staring at this code for a full day now.. I'm probably missing something fairly easy. If you could point my problem out to me.. that'd be great.

try
{
db.connect();
}
catch (ClassNotFoundException e)
{
throw new ServletException("Database drivers not available", e);
}
catch (SQLException e)
{
throw new ServletException("Database URL is wrong", e);
}
try
{
String f_foundimg = v_animg+".jpg";
String sql0 = "update K9Manager set foundimg = ? where intakeno = " + v_animg;
PreparedStatement ps0 = db.createPreparedStatement(sql0, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ps0.clearParameters();
ps0.setString( 1, f_foundimg );
int RowsUpdated = ps0.executeUpdate();
ps0.close();
db.close();
}
 
A try block is required to have at least one catch block or one finally block. There is no way around this, it is a syntax rule. Your second try block does not have either a catch or a finally, it will never compile. Read the Java Language Specification for more details:
More logically, why would you ever want a to put code into a try block without a catch or finally? Isn't that logically the same as no try block at all?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top