📄 dbconnect.java
字号:
package com.wczy.common.db;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.util.ResourceBundle;
public class DBConnect {
private static String driver1, url1, user1, password1;
static {
ResourceBundle bundle = ResourceBundle
.getBundle("com.wczy.common.db.db");
driver1 = bundle.getString("driver");
url1 = bundle.getString("url");
user1 = bundle.getString("user");
password1 = bundle.getString("password");
}
public static Connection getConnection() {
try {
Class.forName(driver1);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
return (Connection) DriverManager.getConnection(url1, user1,
password1);
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public static Connection closeConnection(Connection con) {
if (con != null)
try {
con.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
return con;
}
public static void main(String[] args) {
System.out.println(getConnection());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -