📄 conn.java
字号:
package ksnb;
import java.util.*;
import java.sql.*;
import java.net.*;
public class conn {
Connection con=null;
public conn() throws connException{
String driver = null;
String user = null;
String pass = null;
String dbURL = null;
//生成Properties对象,用来获取配置文件(config)内容
java.util.Properties properties = null;
try {
properties = PropertiesManager.getProperties("config");
driver = properties.getProperty("jdbc.driver");
user = properties.getProperty("jdbc.user");
pass = properties.getProperty("jdbc.password");
dbURL = properties.getProperty("jdbc.dbURL");
//连接数据库
Class.forName(driver);
con= DriverManager.getConnection(dbURL, user, pass);
System.out.println("连接数据库成功!");
}
catch (java.io.FileNotFoundException e) {
throw new connException("JDBC Properties File Read Error!");
} catch (MissingResourceException e) {
throw new connException("JDBC Properties File Not Found!");
} catch (ClassNotFoundException e) {
throw new connException("No Driver Available!");
} catch (SQLException se) {
throw new connException(se.getMessage());
}
}
public Connection getConncetion() throws connException {
return con;
}
public void conClose(){
try{
con.close();
}catch(Exception e){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -