为什么写这样一个函数,在调用时提示: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");