1 import java.sql.Connection; 2 import java.sql.DriverManager; 3 4 private static final String URI = "jdbc:oracle:thin:@localhost:1521:orcl" ; 5 // 驱动路径 6 private static final String USER = "testUser"; // 数据库名 7 private static final String PWD = "admin"; // 数据库密码 8 /-- 9 - 连接数据库的方法 10 - @ return 11 -/ 12 public Connection getConn(){ 13 try { 14 Class.forName("oracle.jdbc.driver.OracleDriver"); // Oracle驱动加载 15 return DriverManager.getConnection(URI,USER,PWD); // 创建连接对象 16 } catch (Exception e) { 17 // TODO Auto-generated catch block 18 e.printStackTrace(); 19 return null ; 20 } 21 }