异常处理的问题

airfox2000 airfox2000 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写了这样一个函数
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;
去掉则正常了,但这不符合要求啊,请高手帮忙哦!

...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
airfox2000
Java 51,407 成员 86,132 内容