今天爱分享给大家带来写一个用 jdbc 连接并访问 oracle 数据的程序代码【面试题详解】,希望能够帮助到大家。
private final static String driverString = "oracle.jdbc.driver.OracleDriver"; private final static String url="jdbc:oracle:thin:@localhost:1521:orcl"; public static Connection getOracleDB() { Connection conn=null; try { Class.forName(driverString); conn= DriverManager.getConnection(url,"scott","123"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } retturn conn; }