0

SAP HANA DB connection works fine in console application, but when calling from service or web application same thing is not working. Its showing error like No suitable driver. I have added ngdbc.jar. I have used Websphere8.5 server and java 1.6

Class.forName("com.sap.db.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:sap://hostname:30015/?autocommit=false&user=myuser&password=mypassword");
SriniV
  • 10,123
  • 14
  • 53
  • 81
Ram
  • 9
  • 1
  • 3
  • "No suitable driver" suggests to me that the driver class was loaded, but the URL syntax was wrong. – duffymo Nov 02 '17 at 12:02
  • 1
    JDK 6? You need to upgrade immediately. That JDK is long past the end of its support life. JDK 8 is the only supported version. JDK 9 is just out. You need to think about currency. – duffymo Nov 02 '17 at 12:07
  • Duffymo, Can you tell me the correct URL syntax ? – Ram Nov 02 '17 at 12:12
  • No, I don't use SAS HANA. Here's the help: https://help.sap.com/doc/0eec0d68141541d1b07893a39944924e/2.0.01/en-US/ff15928cf5594d78b841fbbe649f04b4.html – duffymo Nov 02 '17 at 12:25

1 Answers1

0

Not to belabor the point made above, your JDK will go out of service in April 2018, consider moving to Java 8 now. When you say "DB connection works fine in console application" I assume you mean that you're able to test the connection from the console successfully. From the snippet you pasted, the reason your application is failing is that you're not using the Datasource that you've configured in WAS and that is being used by the test connection. Instead, you're attempting to directly access the DriverManager which will bypass the server's management of JDBC, including connection and statement pooling. The class is failing to load because the application classpath isn't configured to directly load those classes. A Java EE app will typically inject the Datasource you configured in WAS into your app via a resource-ref, @Datasource or other means. This SO post explains the difference between a Datasource and a DriverManager.

F Rowe
  • 1,825
  • 1
  • 8
  • 10