1 import java.sql.Connection; 2 import java.sql.DriverManager; 3 4 private static final String URI = "jdbc:oracle:thin:@localhost:1521:orcl"; 5 //驱动路径 6private static final String USER = "testUser";//数据库名 7private static final String PWD = "admin"; //数据库密码 8 /-- 9- 连接数据库的方法10- @return11-/12public 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 block18 e.printStackTrace();19 return null;20 }21}
如果觉得《java JDBC连接Oracle数据库的方法》对你有帮助,请点赞、收藏,并留下你的观点哦!