Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am writing a piece of JDBC connection code.
try{
Connection con=null;
PreparedStatement pstmt=null;
----------
---------
---------
/* Declared the connection here*/

}
catch(Exception ex)
{
out.println("Unable to connect");
}
finally{
pstmt.close();
con.close();
}

Here im getting error for pstmt and con....cannot find symbol.
Kindly help
Posted
Updated 3-Jun-12 18:56pm
v2

1 solution

Because your variables pstmt and con are declared inside the try block, they are out of scope (cannot be accessed) in the catch block.
Move their declarations before try.

Peter
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900