0

I am programming a database application in Java and would like to use java modules. The following code crashes with an error:


package dm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public static void main(final String[] args) {
      final String dbUrl =
         "jdbc:oracle:thin:@ldap://server/database";

      try {

         final Connection connection =
            DriverManager.getConnection(dbUrl, "user", "password");
      } catch (final SQLException e) {
         e.printStackTrace();
      }
   }

as module-info.java I use:

module sandbox2 {

   exports dm;
   requires java.sql;
}

When I run this code, I get the following error message

java.sql.SQLException: ORA-17858: JNDI package failure: javax.naming.NamingException: Could not resolve a valid ldap host
https://docs.oracle.com/error-help/db/ora-17858/
        at oracle.jdbc.driver.T4CConnection.handleLogonNetException(T4CConnection.java:1615)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:1137)
        at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:1178)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:105)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:886)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:693)
        at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
        at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
        at sandbox2/dm.App2.main(App2.java:18)
Caused by: oracle.net.ns.NetException: ORA-17858: JNDI package failure: javax.naming.NamingException: Could not resolve a valid ldap host
https://docs.oracle.com/error-help/db/ora-17858/
        at oracle.net.jndi.JndiAttrs.initializeLDAPContext(JndiAttrs.java:310)
        at oracle.net.jndi.JndiAttrs.<init>(JndiAttrs.java:165)
        at oracle.net.resolver.AddrResolution.<init>(AddrResolution.java:406)
        at oracle.net.ns.NSProtocol.<init>(NSProtocol.java:247)
        at oracle.net.ns.NSProtocolNIO.<init>(NSProtocolNIO.java:148)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:1000)
        ... 7 more
Caused by: javax.naming.NamingException: Could not resolve a valid ldap host
        at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getContextFromEndpoints(LdapCtxFactory.java:187)
        at java.naming/com.sun.jndi.ldap.LdapCtxFactory.lambda$getUsingURL$0(LdapCtxFactory.java:197)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:570)
        at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:195)
        at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:241)
        at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:160)
        at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:90)
        at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:730)
        at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
        at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
        at java.naming/javax.naming.InitialContext.<init>(InitialContext.java:208)
        at java.naming/javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:101)
        at oracle.net.jndi.JndiAttrs.initializeLDAPContext(JndiAttrs.java:295)
        ... 12 more

If I delete module-info.java the code runs without errors, but I want to use java moduls. Does anyone know how to specify the jdbc driver correctly in module-info.java or does anyone have another solution? I include the jdbc driver with a maven build file:

<dependencies>
      <dependency>
         <groupId>com.oracle.database.jdbc</groupId>
         <artifactId>ojdbc11</artifactId>
         <version>23.4.0.24.05</version>
      </dependency>
</dependencies>

Thanks

changed jdbc driver version, hoped resolves the problem, but didn't

8
  • 2
    Does adding requires java.naming; help? Commented Jun 5, 2024 at 13:40
  • Your IDE such as IntelliJ should help by suggesting changes to the module-info.java file. Commented Jun 5, 2024 at 13:51
  • By the way, DataSource. And oracle.jdbc.datasource. Commented Jun 5, 2024 at 13:52
  • @Slaw too bad, the addition of requires java.naming did not help, thanks Commented Jun 5, 2024 at 15:52
  • 1
    Is the SQLException the root cause? Or are there Caused by after it? Commented Jun 5, 2024 at 18:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.