📄 connectionutil.java
字号:
package com.amaker.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
public class ConnectionUtil {
public Connection getConnection() {
/*String username = "root";
String password = "1";
String url = "jdbc:mysql://localhost:3306/struts_db";
String driver = "com.mysql.jdbc.Driver";
*/
String username =null;
String password = null;
String url = null;
String driver = null;
Properties prop = new Properties();
try {
prop.load(this.getClass().getClassLoader().getResourceAsStream("DBConfig.properties"));
username = prop.getProperty("username");
password = prop.getProperty("password");
url = prop.getProperty("url");
driver = prop.getProperty("driver");
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
ConnectionUtil cu = new ConnectionUtil();
Connection conn = cu.getConnection();
System.out.println(conn);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -