Update DBConnection.java

This commit is contained in:
xixu-me committed 2024-07-01 22:17:53 +08:00
1 parent d92cf50c38
commit 8ec30f25f7
1 file changed
+29 -10
+29 -10
View File
@@ -1,26 +1,45 @@
package server.tools;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DBConnection {
private String driverName;
private String url;
private String user;
private String password;
private final static String driverName = "com.mysql.cj.jdbc.Driver";
private final static String url = "jdbc:mysql://localhost:3306/lda?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
private final static String user = "root";
private final static String password = "516849";
// 加载驱动
static {
try {
Class.forName(driverName);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
return null;
Connection connection = null;
try {
connection = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
public static void close(Connection con, PreparedStatement pst) {
try {
if (pst != null) {
pst.close();
}
if (con != null) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}