on 01-16-2014 12:52 PM
Hello everyone,
I have some trouble with the ngdbc.jar driver from the HANA client. This file is supposed to handle all JDBC connections to HANA. It's working perfectly in my Java application on Windows. On Linux I can start its inbuilt GUI via "java -jar ngdbc.jar" and it works there as well. But it is not working is when I run the same Java application on Linux and I'm wondering why? Maybe you can help.
Here is a part of the code:
Connection con = DriverManager.getConnection("jdbc:sap://" + servername + ":3" + instancename + "15/", username, password);
On Windows this works, on Linux no matter what I try either this exception is thrown:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Or this one:
java.sql.SQLException: No suitable driver
And "DriverManager.getDriver("jdbc:sap://")" returns no entries when running on Linux, but on Windows.
Hope somebody has worked with this driver in combination with Java and Linux already and can give a hint.
Thanks,
Markus
Hi Markus,
have you tried including the jar file to the class search path?
java -cp ngdbc.jar <your class files>
That does work for me...
Lars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for that hint!
I'm not familiar with any of the java start parameters except for -jar. But a co-worker could use it and found with a little research another hint which I used to solve the problem.
So the full solution which worked now to use the ngdbc.jar driver on Linux is:
The -cp parameter is not necessary in this case.
I used
Class.forName("com.sap.db.jdbc.Driver");
in my code before instead of this one
Class.forName("com.sap.db.jdbc.Driver").newInstance();
-> So that was actually the problem. <-
Thank you all,
Markus
Hi Markus,
Good you have solve the problem, but it does not seem to work as it should !
But I think this is related to IDE and it class loader.
The JDBC 4 spec requires a driver to register itself when the class is loaded, and the class is loaded via Class.forName().
In JDBC 4 the drivers are able to also loaded automatically just by being on the class path.
DriverManager.registerDriver() manually is potentially dangerous since it actually causes the
Driver to be registered twice. If your code requires you to deregister a Driver to prevent a memory leak then you would only end up deregistering it once and leave a second instance registered.
The JDBC 4 DriverManager methods getConnection and getDrivers have been enhanced to
support the Java Standard Edition Service Provider mechanism.
JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver.
This file contains the name of the JDBC drivers implementation of java.sql.Driver.
If you add Some small code like this to your sample it will show what driver is registered
List drivers = Collections.list(DriverManager.getDrivers());
for(int i=0;i<drivers.size();i++){
Driver driver = (Driver)drivers.get(i);
String driverName = driver.getClass().getName();
System.out.println("Driver "+i+":::"+driverName);
Will give you output as depend on what is loaded.
Driver 0:::sun.jdbc.odbc.JdbcOdbcDriver
Driver 1:::com.sap.db.jdbc.Driver
Niclas
Hello,
Are you binaries for Linux from HANA client on windows?
Thanks,
Sunny
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again,
I used the redistributable driver from here: https://hanadeveditionsapicl.hana.ondemand.com/hanadevedition/ -> HANA driver
It's a Java .jar-library which should be platform independent.
Thanks,
Markus
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.