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

Dav*_*son 1 java sap jdbc hana

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

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

    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;  
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢你的任何帮助.

我得到的连接错误是:

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)
Run Code Online (Sandbox Code Playgroud)

Dav*_*son 9

我使用的是不正确的SAP jar.当我需要HANA客户端jar(ngdbc.jar)时,我正在使用sapdbc.jar.在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();
}
Run Code Online (Sandbox Code Playgroud)