package com.msit.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* 数据库工具类
*/
public class SqlHelper {
// 连接需要的数据 (这些数据直接写到加密后的数据文件中)
private static String driverName = "com.mysql.jdbc.Driver";
private static String url = "jdbc:mysql://127.0.0.1:3306/vip?user=root&password=root";
// 声明静态连接对象
private static Connection connection = null;
// 编写静态块(比构造函数还早) 用来加载驱动类
static {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}// end
// 获得连接对象
public static Connection getConnection() {
// 创建连接对象
try {
connection = DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}// end
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* 数据库工具类
*/
public class SqlHelper {
// 连接需要的数据 (这些数据直接写到加密后的数据文件中)
private static String driverName = "com.mysql.jdbc.Driver";
private static String url = "jdbc:mysql://127.0.0.1:3306/vip?user=root&password=root";
// 声明静态连接对象
private static Connection connection = null;
// 编写静态块(比构造函数还早) 用来加载驱动类
static {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}// end
// 获得连接对象
public static Connection getConnection() {
// 创建连接对象
try {
connection = DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}// end
}