首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

密文数据源联接发池 ConnectionTools 02

2012-08-21 
密文数据源连接发池 ConnectionTools 02/*** 关闭Connection 2011-12-30,Xgw123485*/public static void c

密文数据源连接发池 ConnectionTools 02
/**
     * 关闭Connection 2011-12-30,Xgw123485
     */
    public static void closeConn(Connection conn)
    {
        if (conn != null)
        {
            try
            {
                conn.close();
            }
            catch (Exception e)
            {
                logger.error("close db Connection failure");
                conn = null;
            }
        }
    }

    /**
     * Close PreparedStatement
     */
    public static void closeStmt(PreparedStatement stmt)
    {
        if(stmt!=null)
        {
            try
            {
                stmt.close();
            }
            catch (Exception e)
            {
                logger.error("close PreparedStatement failure.");
                stmt=null;
            }
        }
    }
   
    /**
     * close ResultSet
     */
    public static void closeResult(ResultSet rs)
    {
        if(rs!=null)
        {
            try
            {
                rs.close();
            }
            catch (Exception e)
            {
                logger.error("Close ResultSet failure.");
                rs=null;
            }
        }
    }
    public static void main(String[] args) {
        Connection connection = getConnection();
        try {
            Statement statement = connection.createStatement();
            statement.executeQuery("select 1 from dual");

            statement.close();
            connection.close();
        } catch (SQLException e) {

            e.printStackTrace();
        }
    }
}

热点排行