MySQL数据库连接工具
(一)MySQL数据库连接工具【原始JDBC封装后的数据库连接工具】
(二)MySQL数据库连接工具【Hibernate框架的数据库连接工具】
(一)MySQL数据库连接工具【原始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.