GWT JDBC LDAP connection fails

2020-08-04 10:53发布

问题:

I am trying to connect my GWT application to an ldap server using jdbc, but could not make it work so far.

Here is a code sample of my attempt to connect to it:

    String ldapConnectString = "jdbc:ldap://SERVERIP:389/dc=SERVERNAME,dc=office,dc=COMPANY,dc=com?SEARCH_SCOPE:=subTreeScope";
    java.sql.Connection con;
    try {
        con = DriverManager.getConnection(ldapConnectString,"cn=USERNAME","PASSWORD");

    } catch (SQLException e) {
        System.out.println("An error has ocurred!!!  Connection failed");
        e.printStackTrace();
    }

The example I used to write this is: http://myvd.sourceforge.net/bridge.html

When I run the application I get following error message:

java.sql.SQLException: No suitable driver found for jdbc:ldap://SERVERIP:389/dc=SERVERNAME,dc=office,dc=COMPANY,dc=com?SEARCH_SCOPE:=subTreeScope

I would be thankful for any help

Edit: The code sample I provided is running on server side accessed by RPC. I included 2 jar files in my lib/ directory downloaded from here: http://sourceforge.net/projects/myvd/files/jdbc%20ldap%20bridge/jdbc%20ldap%20bridge%202.1/jdbc-ldap-2.1.zip/download

回答1:

You generally need to register the JDBC driver before you can connect to the backend.

Try something like

DriverManager.registerDriver(new com.octetstring.jdbcLdap.sql.JdbcLdapDriver());

before setting up the connection.

More general information on ways of registering drivers.