zoukankan      html  css  js  c++  java
  • DB的封装

    public class DB
    {
        
        public static Connection getConn()
        {
            Connection conn=null;
            try
            {
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/bbs", "root", "root");
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            return conn;
        }
        
        public static Statement getStatement(Connection conn)
        {
            Statement stmt=null;
            try
            {
                stmt=conn.createStatement();
            }
            catch (SQLException e)
            {
                e.printStackTrace();
            }
            return stmt;
        }
        
        public static ResultSet executeQuery(Statement stmt,String sql)
        {
            ResultSet rs=null;
            try
            {
                rs=stmt.executeQuery(sql);
            }
            catch (SQLException e)
            {
                e.printStackTrace();
            }
            return rs;
        }
        
        public static void close(Connection conn)
        {
            if(conn != null)
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
        }
        
        public static void close(Statement stmt)
        {
            if(stmt != null)
                try
                {
                    stmt.close();
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
        }
        
        public static void close(ResultSet rs)
        {
            if(rs != null)
                try
                {
                    rs.close();
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
        }
    }
  • 相关阅读:
    组合数学总结
    字符串算法总结
    数据结构总结
    CDQ分治(学习笔记)
    网络流(学习笔记)
    string
    water
    mine
    洛谷 P4035 【球形空间产生器】
    洛谷 P3306 【随机数生成器】
  • 原文地址:https://www.cnblogs.com/liu-Gray/p/5251663.html
Copyright © 2011-2022 走看看