zoukankan      html  css  js  c++  java
  • JDBC工具类的提取

    package JDBCUtils;
    
    import java.sql.*;
    
    public class JDBCUtils{
        private static final String driverClass;
        private static final String url;
        private static final String username;
        private static final String password;
    
        static{
            driverClass="com.mysql.jdbc.Driver";
            url="jdbc:mysql:///jdbc?serverTimezone=UTC";
            username="root";
            password="root";
         try{
    loadDriver();
         }catch(ClassNotFoundException e){
           e.printStackTrace();
         }
    }
    public void loadDriver() throws ClassNotFoundException { Class.forName(driverClass); } public static Connection getConnection() throws SQLException { Connection conn = DriverManager.getConnection(url, username, password); return conn; } public static void release(Connection conn, Statement stat) { if (stat != null) { try { stat.close(); } catch (SQLException e) { e.printStackTrace(); } stat = null; } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } conn = null; } } public static void release(ResultSet rs,Connection conn, Statement stat) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } rs = null; } if (stat != null) { try { stat.close(); } catch (SQLException e) { e.printStackTrace(); } stat = null; } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } conn = null; } } }
    try {
    loadDriver();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
  • 相关阅读:
    [hosts]在hosts中屏蔽一级域名和二级域名的写法
    [oracle]查询一个表中数据的插入时间
    [Windows Doc]微软官方文档
    [PL]如果天空是黑暗的,那就摸黑生存
    [LVM]创建LVM卷
    [powershell]获取FCID&Port
    [oracle]解决ora-01034 oracle not available
    [GoogleBlog]new-approach-to-china
    [时钟]配置日期时间并同步到硬件
    [rhel]安装oracle11g
  • 原文地址:https://www.cnblogs.com/shouyaya/p/12319133.html
Copyright © 2011-2022 走看看