title: How to connect to Oracle Cloud DDBB using JDBC Thin Driver and Oracle Wallet
body: <p>I am following the <a href="https://docs.oracle.com/en/cloud/paas/autonomous-data-warehouse-cloud/user/connect-jdbc-thin-wallet.html#GUID-20656D84-4D79-4EE9-B55F-333053948966" rel="nofollow noreferrer">guide</a> to connect from a java application using the IDE IntelliJ to an Oracle Cloud Database.</p>
  <p>I meet the <a href="https://docs.oracle.com/en/cloud/paas/autonomous-data-warehouse-cloud/user/connect-jdbc-thin-wallet.html#GUID-EBBB5D6B-118D-48BD-8D68-A3954EC92D2B" rel="nofollow noreferrer">prerequisites</a> since:</p>
  <ul>
  <li>I have a Database in Oracle Cloud service</li>
  <li>I downloaded the wallet and I placed the files in the src directory of my workspace.</li>
  <li>I am using last JDK 14</li>
  <li>I am using the ojdbc8.jar</li>
  <li>And I downloaded as well the oraclepki, osdt_cert, and osdt_core jars, all of them added as java libraries in my test project</li>
  </ul>
  <p>The recommended BD_URL is never working. I always get: <strong>java.net.UnknownHostException and oracle.net.ns.NetException: The Network Adapter could not establish the connection</strong></p>
  <pre><code>DB_URL= &quot;jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=testgerard_high)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=testgerard_high)))&quot;
  </code></pre>
  <p>Then I found in <a href="https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=249272212021220&amp;id=1457274.1&amp;_afrWindowMode=0&amp;_adf.ctrl-state=gydl1iqzq_259" rel="nofollow noreferrer">Oracle support</a> that it could be added to the wallet directory, but the same issue.</p>
  <pre><code>DB_URL= &quot;jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=testgerard_high)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=testgerard_high))(SECURITY = (MY_WALLET_DIRECTORY = src\\Wallet_testGerard)))&quot;
  </code></pre>
  <p>If I switch to a connection string using 18.3 JDBC driver which should work for my settings, then I get the error: <strong>Invalid connection string format, a valid format is: &quot;host:port:sid&quot;</strong></p>
  <pre><code>DB_URL=&quot;jdbc:oracle:thin:@testgerard_high?TNS_ADMIN=src\\Wallet_testGerard&quot;;
  </code></pre>
  <p>Finally, I have seen <a href="https://stackoverflow.com/questions/57341480/invalid-connection-string-format-error-when-trying-to-connect-to-oracle-using">here</a> a way to inform the wallet folder out of the BD_URL so I do not get the invalid format exception:</p>
  <pre><code>System.setProperty(&quot;oracle.net.tns_admin&quot;,&quot;src\\Wallet_testGerard&quot;);
  </code></pre>
  <p>Now it is trying to connect but it fails after 60 seconds with the <strong>exception:sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target</strong></p>
  <p>I adapted an oracle example, here is my code:</p>
  <pre><code>import java.sql.SQLException;
  import java.sql.DatabaseMetaData; 
  import oracle.jdbc.pool.OracleDataSource;
  import oracle.jdbc.OracleConnection;
  
  
  public class OracleDataSourceSample
  {
      final static String DB_URL=&quot;jdbc:oracle:thin:@testgerard_high&quot;;
      //final static String DB_URL=&quot;jdbc:oracle:thin:@testgerard_high?TNS_ADMIN=src\\Wallet_testGerard&quot;;
      //final static String DB_URL= &quot;jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=testgerard_high)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=testgerard_high))(SECURITY = (MY_WALLET_DIRECTORY = src\\Wallet_testGerard)))&quot;;
  
      final static String DB_USER = &quot;hr&quot;;
      final static String DB_PASSWORD = &quot;hr&quot;;
  
      public static void main (String args[]) throws SQLException, ClassNotFoundException {
  
          System.setProperty(&quot;oracle.net.tns_admin&quot;,&quot;src\\Wallet_testGerard&quot;);
          Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);
          OracleDataSource ods = new OracleDataSource();
          ods.setURL(DB_URL);
          ods.setUser(DB_USER);
          ods.setPassword(DB_PASSWORD);
  
          // With AutoCloseable, the connection is closed automatically.
          try (OracleConnection connection = (OracleConnection)
                  ods.getConnection()) {
              // Get the JDBC driver name and version
              DatabaseMetaData dbmd = connection.getMetaData();
              System.out.println(&quot;Driver Name: &quot; + dbmd.getDriverName());
              System.out.println(&quot;Driver Version: &quot; +
                      dbmd.getDriverVersion());
              System.out.println(&quot;Database Username is: &quot; +
                      connection.getUserName());
          }
      }
  }
  </code></pre>