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();
    }
  • 相关阅读:
    Redis服务器配置
    Spark History Server配置使用
    CentOS7.3安装Nginx
    U盘安装CentOS7的最终解决方案
    iconfont_3种引用方式
    div+css 让一个小div在另一个大div里面 垂直居中
    JavaScript数组方法
    addEventListener()和removeEventListener()
    js获取网页高度
    Linux修改命令行样式
  • 原文地址:https://www.cnblogs.com/shouyaya/p/12319133.html
Copyright © 2011-2022 走看看