0 Replies Latest reply: May 9, 2013 8:16 AM by ThomasH RSS

    getConnection(String URL) vs. (String URL, String user, String password)

    ThomasH
      Hi,

      would have a question referring to the documention at http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html where the forms of getConnection are described.

      I would like to convert from using a signature that takes the URL, user name, and password as separate parameters to using a signature that takes the URL, user name, and password all as part of a URL parameter.

      While I was able to successfully connect to my database using the form getConnection(String URL, String, user, String password); I am not able to achieve the same when using getConnection(String URL).

      Here are the code snippets, maybe someone can point out the reason why the second approach is not working?

      approach 1 - working fine

      String driver = "oracle.jdbc.driver.OracleDriver";
      try {
                Class.forName(driver);
                } catch(java.lang.ClassNotFoundException e) {
                }
                String connectionURL = "jdbc:oracle:thin:@localhost:1521:PMT";
                String pgUser = "\"James.Smith@000\"";
                String pgPwd = "\"js\"";
           try {

                     Connection conn = DriverManager.getConnection(connectionURL, pgUser, pgPwd);

      approach 2 - error: java.sql.SQLException: The Network Adapter could not establish the connection
      String driver = "oracle.jdbc.driver.OracleDriver";
      try {
                Class.forName(driver);
                } catch(java.lang.ClassNotFoundException e) {
                }
      String connectionURL = "jdbc:oracle:thin:\"James.Smith@000\"/\"js\"@localhost:1521:PMT";
           try {

                     Connection conn = DriverManager.getConnection(connectionURL);

      Thanks a lot in advance

      Kind regards
      Thomas