java jdbc 删除不干净sa登录失败_问题有点棘手,JDBC的关闭连接问题

conn是已经获得的一个连接,stmt是Statement的一个对象,rst是ResultSet的一个对象

它是按种类名称,来查询这个类是否在表中;

在CategoryManager.java中定义了一个方法,代码如下(这个类是编译通过的)

public boolean havaCategory(String cateName)throws Exception{

String correct =”select categoryID from category where categoryNAME=”””+cateName+””””;

stmt = conn.createStatement();

rst = stmt.executeQuery(correct);

try{

if(cateName==null || cateName.equals(“”)){

return false;

}

if(!rst.next()){

return false;

}

return true;

}catch(SQLException e){

return false;

}catch(Exception ex){

return false;

}finally{

try{

stmt.close();

conn.close();

}catch(SQLException ex){

return false;

}

}//end finally block;

}//end cateNameToID method;

我在另一个类中调用它:

CategoryManager cateManager = new CategoryManager();

boolean havaCate = cateManager.havaCategory(“123”);

在编译的时候,告诉我:

unreported exception java.lang.Exception; must be caught or declared to be thrown

大家看我哪里写的不对吗?

**但如果我不关闭连接,就不会出现这种情况,但这样使的人多了肯定会出问题的呀……请大家帮忙看下……谢了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值