无法通过JDBC连接到远程HANA数据库

无法通过JDBC连接到远程HANA数据库

问题描述:

我正在从笔记本电脑上运行一个小型JAVA程序,试图通过JDBC连接到我们的HANA服务器,以获取可以吗?"原型.

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

我知道可以通过JDBC连接连接到远程HANA服务器. 但是,我不能.这是我使用sapdbc.jar文件从JAVA中使用的方法.我只是在这里测试连接.

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;  

该实例为00,但是如果需要,则看不到将其包含在连接字符串中的位置.我已经仔细检查了所有属性.

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.

我们的HANA服务器由另一家公司托管,尽管对它的访问位于我们的网络内部.这可能是原因吗?

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

感谢您的协助.

我得到的连接错误是:

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)

我使用了不正确的SAP jar.当我需要HANA客户端jar(ngdbc.jar)时,我正在使用sapdbc.jar.在jar和驱动程序切换之后,一切都连接了.

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();
}