Connection conn = null;
Statement statement = null;
try {
conn = getConnection2();
String sql = "insert into userinfo(username,password)values('avas1','dsfad')";
statement = conn.createStatement();
statement.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
statement.close();
conn.close();
}
如果我将conn 和statement放到try里声明,那么finally就会提示找不到这两个变量
这是为什么?
请问Try{}catch{}{}finally{}变量声明的一个小问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
6条回答
threenewbee 2016-08-06 12:10关注和try catch没有关系,只要是块,就符合这个规则。包括if for while switch等,也包括你不使用以上关键字,故意就写一个块。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报