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
大家看我哪里写的不对吗?
**但如果我不关闭连接,就不会出现这种情况,但这样使的人多了肯定会出问题的呀……请大家帮忙看下……谢了