J.E.Y J.E.Y - 1 month ago 7
Java Question

what's the data source url for LDAP type

I am using Spring jdbc api to connect to a Oracle database. Only LDAP style of connection is provided to that particular database, and I succeeded in making the connection from Oracle's database client SQL developer.

One thing seems odd to me is the format of the connection string:

xyz.loc.biz.com:4050:4049


it worked when applied in SQL developer, however you would notice that there are two numbers which supposedly represent port number, but why two?

Nevertheless I used the above url in my code, which looks like:

@Bean
public DataSource getDataSource(){
SimpleDriverDataSource ds = new SimpleDriverDataSource();
ds.setUrl("jdbc:oracle:thin:@ldap://xyz.loc.biz.com:4050:4049/...");

ds.setDriver(new OracleDriver());
ds.setUsername("xxxxxx");
ds.setPassword("yyyyyy");

try(Connection conn = ds.getConnection()){
log.info("conn={}",conn);
}catch(Exception e){
e.printStackTrace();
};
return ds;
}


Not surprisingly it shows an error like:

java.lang.NumberFormatException: For input string: "4050:4049"


Anyone can help?

Settings in SQL developer:

enter image description here

Answer

It seems that if you specify two port numbers the first is used for the ldap protocol, the second for the ldaps protocol (found a hint at http://yong321.freeshell.org/oranotes/OracleConnectionSetup.html, the following is more definitive: http://docs.oracle.com/cd/B28359_01/network.111/b28317/ldap.htm).

It can be that the Oracle JDBC driver does not understand this syntax. Please try if one of these alternative connection strings work for you:

ds.setUrl("jdbc:oracle:thin:@ldap://xyz.loc.biz.com:4050/...");
ds.setUrl("jdbc:oracle:thin:@ldaps://xyz.loc.biz.com:4049/...");