Trouble connecting to a remote HANA database via JDBC

Davidson picture Davidson · Oct 22, 2013 · Viewed 18k times · Source

I'm running a small JAVA program from my laptop trying to connect via JDBC to our HANA server for a "Can we?" prototype.

I understand it's possible to connect via JDBC connection to a remote HANA server. However, I cannot. Here's the methodology I'm using from the JAVA using the sapdbc.jar file. I'm just testing a connection here.

    DataSourceSapDB ds = new DataSourceSapDB();
    ds.setServerName("10.x.x.xxx");
    ds.setPort(30015);
    ds.setDatabaseName("dbNAME");
    ds.setUser("myUser");
    ds.setPassword("myPassword");
    Connection c = ds.getConnection();

    if (c == null) return;  

The instance is 00 but don't see where to include it in the connect string, if it is required. I've double-checked all the properties.

Our HANA server is hosted by another company though access to it is inside our network. Could this be a reason?

Thanks for any assinstance.

The connection error I get is:

com.sap.dbtech.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: Cannot connect to jdbc:sapdb://10.x.x.xxxx:30015/dbNAME [Connect reply receive failed [Connection reset].].
    at com.sap.dbtech.jdbc.DriverSapDB.connect(DriverSapDB.java:178)
    at com.sap.dbtech.jdbcext.DataSourceSapDBBase.openPhysicalConnection(DataSourceSapDBBase.java:374)
    at com.sap.dbtech.jdbcext.DataSourceSapDB.getConnection(DataSourceSapDB.java:49)
    at com.glazers.hana.utils.HanaStoredProcedure.execute(HanaStoredProcedure.java:37)
    at com.glazers.hana.utils.HanaStoredProcedure.main(HanaStoredProcedure.java:24)

Answer

Davidson picture Davidson · Oct 23, 2013

I was using the incorrect SAP jar. I was using sapdbc.jar when I needed the HANA client jar (ngdbc.jar). It all connected after that jar and driver switch.

try {
    Class.forName("com.sap.db.jdbc.Driver");

    String url = "jdbc:sap://xx.x.x.xxx:30015/?databaseName=DBNAME";
    String user = "user";
    String password = "password";

    Connection cn = java.sql.DriverManager.getConnection(url, user, password);

    ResultSet rs = cn.createStatement().executeQuery("CALL MY_SCHEMA.STORED_PROC");

    // ... do whatever with the results ...

} catch (Exception e) {
    e.printStackTrace();
}