尽管有try / catch块,JSP仍未处理SQLException错误

时间:2015-07-31 23:21:52

标签: mysql jsp jdbc

我正在看一个回溯的代码。看起来像这样

public String MaxID() throws SQLException {

    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;

    try {
    DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
    conn = DriverManager.getConnection(get_db_url(), get_db_id(), get_db_pw());
    stmt = conn.createStatement();
    String sql = null;
    sql = "select MAX(id)+1 AS count from tbl1";
    rset = stmt.executeQuery (sql);
    rset.next();         
    String newId = rset.getString("count");
    if (newId == null)
        newId = "1";     
        return newId;
    } catch (SQLException e) {

        return ("<P> SQL error: <PRE> " + e + " </PRE> </P>\n");

    } finally {
        if (rset!= null) rset.close();
        if (stmt!= null) stmt.close();
        if (conn!= null) conn.close();
    }

}

当我尝试运行它时,我收到以下输出:

jsp文件中的第146行:/functions.jsp发生错误 未处理的异常类型SQLException 143:ResultSet rset = null; 144: 145: 146:DriverManager.registerDriver(new org.gjt.mm.mysql.Driver()); 147:conn = DriverManager.getConnection(get_db_url(),get_db_id(),get_db_pw()); 148:stmt = conn.createStatement(); 149:String sql = null;

我无法理解为什么。它是以适当的方式处理的(根据我在文档中读到的内容)

0 个答案:

没有答案