Update DBConnection.java
This commit is contained in:
1 parent
d92cf50c38
commit
8ec30f25f7
1 file changed
+29
-10
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user