11.28

package com.attendance.util;

import java.sql.*;

public class DBUtil {
private static final String URL = "jdbc:mysql://localhost:3306/attendance_db?useSSL=false&characterEncoding=utf8";
private static final String USER = "root";
private static final String PASSWORD = "123456";

static {
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

public static Connection getConnection() throws SQLException {
    return DriverManager.getConnection(URL, USER, PASSWORD);
}

public static void close(Connection conn, Statement stmt, ResultSet rs) {
    try {
        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (conn != null) conn.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

}

posted @ 2025-12-08 15:14  Cx330。  阅读(3)  评论(0)    收藏  举报