try {
Class.forName("oracle:jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:数据库SID";
String user ="数据库用户名";
String password = "数据密码";
conn = DriverManager.getConnection(url, user, password);
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
public static void tryClose(ResultSet set, Statement stat, Connection conn) {
if (set != null) {
try {
set.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
set = null;
}
if (stat != null) {
try {
stat.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
stat = null;
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
conn = null;
}
}
}
public static boolean testConn() {
boolean isConn = false;
Connection conn = null;
try {
Class.forName(ConfigBean.getForName());
String url = ConfigBean.getUrl();
String user = ConfigBean.getUser();
String password = ConfigBean.getPwd();
conn = DriverManager.getConnection(url, user, password);
isConn = true;
conn.close();
// TODO 自动生成 catch 块
e.printStackTrace();
// TODO 自动生成 catch 块
isConn = false;
e.printStackTrace();
}
return isConn;