操作Oracle数据库
publicclass DBConnection {
//jdbc:oracle:thin:@localhost:1521:orcl
publicstaticfinal String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
publicstatic Connection conn ;
static{
//获取数据库驱动
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
publicstatic Connection getConn(){
try {
//连接数据库
conn = DriverManager.getConnection(url, "scott", "tiger");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
publicstaticvoid closeConn(Connection conn){
try {
//关闭数据库
if(conn != null && !conn.isClosed()){
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//测试
publicstaticvoid main(String[] args) {
System.out.println(getConn() != null);
}
调用存储过程