import java.sql.*;
import java.util.ResourceBundle;
public class DBIILE {
public static final String driverclass;
public static final String name;
public static final String url;
public static final String pass;
static{
ResourceBundle rb=ResourceBundle.getBundle("db");
driverclass=rb.getString("driverclass");
name=rb.getString("name");
url=rb.getString("url");
pass=rb.getString("pass");
try {
Class.forName(driverclass);//加载数据驱动
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection open() throws SQLException {
Connection conn= DriverManager.getConnection(url,name,pass);//获得数据库连接
return conn;
}
public static void close(Connection conn,PreparedStatement pst){
close(null,conn,pst);
}
public static void close(ResultSet rs, Connection conn, PreparedStatement pst){
if(rs!=null){
try {
rs.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if(pst!=null){
try {
pst.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
}
driverclass=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
name=scott
pass=123456