zoukankan      html  css  js  c++  java
  • JDBC JdbcUtils( 本博多次出现的简陋工具类)

    package test;

    import java.sql.Connection; 
    import java.sql.DriverManager; 
    import java.sql.ResultSet; 
    import java.sql.SQLException; 
    import java.sql.Statement;

    /* 简陋工具类  */ 
    public final class JdbcUtils { 
        private static String url="jdbc:mysql://localhost:3306/world"; 
        private static String user = "root"; 
        private static String password="mysql";

        static { 
            try { 
                Class.forName("com.mysql.jdbc.Driver"); 
            } catch (ClassNotFoundException e) { 
                throw new ExceptionInInitializerError(e); 
            }

        } 
        
        private JdbcUtils() {} 
        
        public static Connection getConnection() throws SQLException { 
            return DriverManager.getConnection(url,user,password); 
        } 
        
        public static void free(ResultSet rs,Statement st,Connection conn) { 
            try { 
                if (rs != null) { 
                    rs.close(); 
                } 
            }catch(SQLException e) { 
                e.printStackTrace(); 
            } 
            finally { 
                try { 
                    if (st != null) { 
                        st.close(); 
                    } 
                } catch(SQLException e){ 
                    e.printStackTrace(); 
                } finally { 
                    if (conn != null) 
                        try { 
                            conn.close(); 
                        } catch (SQLException e) { 
                            e.printStackTrace(); 
                        } 
                } 
            } 
        } 
    }

  • 相关阅读:
    Sampling Distribution of the Sample Mean|Central Limit Theorem
    OS L2-3: Process Creation and Operations
    c++函数重载、内联函数、类、友元
    命名空间及异常处理
    C++继承与多态,代码复用之泛型和模板
    ORB_GMS图像对齐
    ORB对齐
    [转]OpenCV中ORB特征点检测和匹配简单用法
    [转]OpenCV学习笔记】之鼠标的调用
    [转]OpenCV—Mat类
  • 原文地址:https://www.cnblogs.com/flying607/p/3461558.html
Copyright © 2011-2022 走看看