import java.sql.Connection;
import java.sql.DriverManager;
public class Test {
public static void main(String[] args) {
Connection conn=null;
//1、加载驱动
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(ClassNotFoundException e){
System.out.println("加载驱动失败");
}
//2、建立连接
try{
conn=DriverManager.getConnection("jdbc:oracle:thin:epet/accp@localhost:1521:oracle10");
System.out.println("建立连接成功");
}catch(Exception e){
System.out.println("建立连接失败");
}finally{
//3、关闭连接
try{
if(null !=conn){
conn.close();
System.out.println("关闭连接成功");
}
}catch(Exception e){
System.out.println("关闭连接失败");
}
}
}
}