为什么写这样一个函数,在调用时提示:unreported exception,各位请帮忙,谢谢!

xieyj 2004-07-06 02:07:12
//已经配置好了连接池
//数据库连接部分
Context ctx=null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
PrintWriter out = null;

//用于得到记录数
public int getRecord(String strSql)
throws NamingException, SQLException
{
int iResult = 0;
try {
ctx = new InitialContext();
if(ctx == null)
out.println("没有匹配的环境");
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/connectDB");
if(ds == null) {
out.println("没有匹配数据库");
}
conn = ds.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(strSql);
System.out.println(rs.getRow());
iResult = rs.getRow();
} catch (Exception e) {

} finally {
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(conn!=null) conn.close();
if(ctx!=null) ctx.close();
}
return iResult;
}
//调用
int iCount = getRecord("select * from sysobjects");
...全文
93 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xieyj 2004-07-06
  • 打赏
  • 举报
回复
谢谢楼上两位,还是不行
Acylas 2004-07-06
  • 打赏
  • 举报
回复
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(conn!=null) conn.close();
if(ctx!=null) ctx.close();
上面这几个分别加上try {} catch
feiyuwen 2004-07-06
  • 打赏
  • 举报
回复
自己调试

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧