cancel
Showing results for 
Search instead for 
Did you mean: 

JDBC Connection to SAP HANA on Linux systems

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

lbreddemann
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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:

  1. Bind the ngdbc.jar to the project of the IDE
  2. Add 'Class.forName("com.sap.db.jdbc.Driver").newInstance();' right before the getConnection-statement
  3. Connection con = DriverManager.getConnection("jdbc:sap://" + servername + ":3" + instancename + "15/", username, password);
  4. Start the deployed Java project via 'java -jar filename.jar'
  5. Connection established!

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

Former Member
0 Kudos

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

sunny_pahuja2
Active Contributor
0 Kudos

Hello,

Are you binaries for Linux from HANA client on windows?

Thanks,

Sunny

Former Member
0 Kudos

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