(1) MySQL database connection tool [database connection tool encapsulated by original JDBC]

MySQL database connection tool
(1) MySQL database connection tool [original JDBC encapsulated database connection tool]
(2) MySQL database connection tool [Hibernate framework database connection tool]

(1) MySQL database connection tool [database connection tool encapsulated by original JDBC]

Business.java

package com.hk.server.base;

import java.sql.*;

/**
 * Business 类
 *
 * 用于实现和数据库的连接
 *
 * @author: shipleyleo
 * @create: 2023-05-19 18:29:08
 */
public class Business {
   
    
    
    // 加载驱动,创建连接,释放资源
    private static final String driver = "com.mysql.cj.jdbc.Driver";
    private static final String url = "jdbc:mysql://localhost:3306/hk";
    private static final String username = "root";
    private static final String pwd = "******";

    static {
   
    
    
        try {
   
    
    
            Class.forName(driver); // 加载驱动
        } catch (Exception e) {
   
    
    
            e.printStackTrace();
        }
    }

    public static Connection getConnection() {
   
    
    
        Connection con = null;
        try {
   
    
    
            con = DriverManager.getConnection(url, username, pwd); // 建立数据库连接对象
        } catch (Exception e) {
   
    
    
            e.

Guess you like

Origin blog.csdn.net/Shipley_Leo/article/details/130832875