异常处理的问题
写了这样一个函数
public Object executeSingleQuery(String strPoolName,String sqlString)
{
Statement stmt = null;
ResultSet rs = null;
Object returnObject = null;
Connection conn = null;
try{
conn = getConnection(strPoolName);
stmt = conn.createStatement();
rs = stmt.executeQuery(sqlString);
if(rs.next()){
returnObject = rs.getObject(1);
}
rs.close();
stmt.close();
conn.commit();
freeConnection(strPoolName,conn);
}catch (SQLException e){
log(e.toString()+",执行查询语句失败");
rs.close();
stmt.close();
freeConnection(strPoolName,conn);
throw e;
}
return returnObject;
}
提示throw e这行有错,错误提示为
Error #: 360 : unreported exception: java.sql.SQLException; must be caught or declared to be thrown at line 235, column 5
我觉得没有错啊,为什么?当把catch里的
rs.close();
stmt.close();
throw e;
去掉则正常了,但这不符合要求啊,请高手帮忙哦!
public Object executeSingleQuery(String strPoolName,String sqlString)
{
Statement stmt = null;
ResultSet rs = null;
Object returnObject = null;
Connection conn = null;
try{
conn = getConnection(strPoolName);
stmt = conn.createStatement();
rs = stmt.executeQuery(sqlString);
if(rs.next()){
returnObject = rs.getObject(1);
}
rs.close();
stmt.close();
conn.commit();
freeConnection(strPoolName,conn);
}catch (SQLException e){
log(e.toString()+",执行查询语句失败");
rs.close();
stmt.close();
freeConnection(strPoolName,conn);
throw e;
}
return returnObject;
}
提示throw e这行有错,错误提示为
Error #: 360 : unreported exception: java.sql.SQLException; must be caught or declared to be thrown at line 235, column 5
我觉得没有错啊,为什么?当把catch里的
rs.close();
stmt.close();
throw e;
去掉则正常了,但这不符合要求啊,请高手帮忙哦!
...全文
相关推荐
异常处理问题
解决这类问题的方法是仔细检查出错位置,确保每条语句的结尾都有正确的分号。
ios异常处理问题
ios异常处理问题"这一主题关注的是如何有效地检测和处理这些异常,以防止程序的非预期终止。在Objective-C和Swift这两种主要的iOS编程语言中,异常处理机制有所不同。
使用异常处理语句需要注意的几个问题
在Java中,异常处理是通过五个关键字来实现的:`try`, `catch`, `finally`, `throw`, 和 `throws`。下面我们将详细探讨使用异常处理语句时需要注意的问题:1.
使用异常处理输入是,输出三边,不是输出异常,还有输入取钱时也会输出的异常的问题
在编程领域,异常处理是一项至关重要的技能,尤其是在处理用户输入或者执行关键操作时。异常处理主要是为了确保程序在遇到错误或异常情况时能够优雅地处理问题,而不是突然崩溃。
Java异常处理中同时有finally和return语句的执行问题
在Java编程语言中,异常处理机制是通过try-catch-finally结构来实现的。


