How can I connect to a web based Oracle database with Java?

♀尐吖头ヾ 提交于 2019-12-10 12:27:45

问题


I have an account, password and the URL.


回答1:


Use:

Connection connection = null;

try {
   // Load the JDBC driver
   String driverName = "oracle.jdbc.driver.OracleDriver";
   Class.forName(driverName);

   // Create a connection to the database
   String serverName = "127.0.0.1";
   String portNumber = "1521";
   String sid = "mydatabase";
   String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
   String username = "username";
   String password = "password";
   connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
   // Could not find the database driver
} catch (SQLException e) {
   // Could not connect to the database
}

Reference: Connecting to an Oracle Database




回答2:


Just an addendum to OMG Ponies' answer, you will need a couple of items to proceed: 1. A JDBC driver for Oracle on your build path (Oracle offers these drivers for download) 2. The driverName variable in OMG Ponies' code has to be changed to the name of the specific Oracle driver you're using 3. The serverName variable in OMG Ponies' code should NOT be left at 127.0.0.1 but should instead be changed to the server address you mentioned. I only note this because the way you phrased your question implies an unfamiliarity with computer concepts in general and using databases with Java in particular.



来源:https://stackoverflow.com/questions/1793408/how-can-i-connect-to-a-web-based-oracle-database-with-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!