1.数据库工具类

package com.xiaoxiong.util;

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

public class ConnUtil {
    //定义连接数据库参数
    private static String drivers = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/easyui";
    private static String user = "root";
    private static String password = "a123456";
    private static Connection conn = null;
    
    //连接数据库
    public static Connection getConnection(){
        try {
            //加载驱动
            Class.forName(drivers);
            
            //连接数据库
            conn = DriverManager.getConnection(url, user, password);
            
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        return conn;
    }
    
    //关闭数据库
    public void close(){
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
}
ConnUtil

相关文章:

  • 2021-07-05
  • 2021-09-28
  • 2021-12-13
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
猜你喜欢
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2021-09-23
  • 2021-10-26
  • 2022-01-17
  • 2022-12-23
相关资源
相似解决方案