中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

JDBC公共操作類

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
    import java.sql.Connection;  
    import java.sql.DriverManager;  
    import java.sql.ResultSet;  
    import java.sql.SQLException;  
    import java.sql.Statement;  
      
    public class DBUtil {  
        public static final String DRIVER = "com.mysql.jdbc.Driver";  
        public static final String URL = "jdbc:mysql://localhost:3306/db";  
        public static final String USERNAME = "root";  
        public static final String PASSWORD = "root";  
      
        /** 
         * 通過靜態(tài)代碼塊 注冊數(shù)據(jù)庫驅(qū)動(dòng) 
         */  
        static {  
            try {  
                Class.forName(DRIVER);  
            } catch (ClassNotFoundException e) {  
                e.printStackTrace();  
            }  
        }  
      
        /** 
         * 獲得Connection 
         *  
         * @return 
         */  
        public static Connection getConnection() {  
            Connection conn = null;  
            try {  
                conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);  
            } catch (SQLException e) {  
                e.printStackTrace();  
            }  
            return conn;  
        }  
      
        /** 
         * 獲得Statement 
         *  
         * @return 
         */  
        public static Statement getStatement() {  
            Statement st = null;  
            try {  
                st = getConnection().createStatement();  
            } catch (SQLException e) {  
                e.printStackTrace();  
            }  
            return st;  
        }  
      
        /** 
         * 關(guān)閉ResultSet 
         *  
         * @param rs 
         */  
        public static void closeResultSet(ResultSet rs) {  
            if (rs != null) {  
                try {  
                    rs.close();  
                } catch (SQLException e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
      
        /** 
         * 關(guān)閉Statement 
         *  
         * @param st 
         */  
        public static void closeStatement(Statement st) {  
            if (st != null) {  
                try {  
                    st.close();  
                } catch (SQLException e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
      
        /** 
         * 關(guān)閉Connection 
         *  
         * @param conn 
         */  
        public static void closeConnection(Connection conn) {  
            if (conn != null) {  
                try {  
                    conn.close();  
                } catch (SQLException e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
      
        /** 
         * 關(guān)閉全部 
         *  
         * @param rs 
         * @param sta 
         * @param conn 
         */  
        public static void closeAll(ResultSet rs, Statement sta, Connection conn) {  
            closeResultSet(rs);  
            closeStatement(sta);  
            closeConnection(conn);  
        }  
      
    }  

標(biāo)簽: Mysql 代碼 數(shù)據(jù)庫

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇: 經(jīng)典算法10:回溯法求解八皇后

下一篇:python代碼實(shí)例大小寫轉(zhuǎn)換,首字母大寫,去除特殊字符