|
Connection con= DriverManager.getConnection(url,"123","123");
Statement stmt = con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
假设有很长的代码(20行吧)
再假设这20行内的代码报出SQLException 或是其它结束
rs.close
stmt.close
con.close
上面三句都不会执行,就不能关闭连接
怎么能又关了数据库所有连接 方法还向上抛出异常
这个方法 throws SQLException
try catch 块的话!太大了!!
|
|