阅读背景:

JDBC 通过Statement 执行更新操作 2.1

来源:互联网 
        /*
     * 通过的更新方法:包括 insert、update、delete
     * 
     */
    public void update(String sql) {
        Connection conn = null;
        Statement statement = null;
        
        try {
            conn = getConnection2();
            statement = conn.createStatement();
            statement.executeUpdate(sql);
            
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            // JDBCtools.release(statement,conn); 
            // 下面的全部可以替换为这一句话
            
            if(statement != null) {
                try {
                    statement.close();
                } catch (Exception e2) {
                    // TODO: handle exception
                    e2.printStackTrace();
                }
            }
            
            if(conn != null) {
                try {
                    conn.close();
                } catch (Exception e2) {
                    // TODO: handle exception
                    e2.printStackTrace();
                }
            }
        }
    }        /*
     * 通过的更新方法:包括 insert、update、dele



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: