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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19527109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:02:09  来源:igfitidea点击:

Trouble connecting to a remote HANA database via JDBC

javajdbcsaphana

提问by Davidson

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

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

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.

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

    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.

实例是 00,但如果需要,看不到将它包含在连接字符串中的何处。我已经仔细检查了所有属性。

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

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

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)

采纳答案by Davidson

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.

我使用了不正确的 SAP jar。当我需要 HANA 客户端 jar (ngdbc.jar) 时,我正在使用 sapdbc.jar。在那个罐子和驱动程序开关之后,这一切都连接起来了。

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

回答by JSNinja

Yes you are right you need to use the ngdbc.jar to make the connection.

是的,您说得对,您需要使用 ngdbc.jar 进行连接。

The instance number is included in the port no. that you are connecting to.

实例号包含在端口号中。您正在连接的。

e.g if your port no. is 30015, then 00 is the instance.

例如,如果您的端口号。是 30015,那么 00 就是实例。

Hope this helps.

希望这可以帮助。