SAP HANA 主机名 JDBC 驱动程序

3

我正在尝试将我的Java程序连接到HANA数据库。然而,我无法这样做,因为我必须通过一个URL将我的程序连接到数据库,而我不知道这个URL是什么。我在网上注册了一个HANA试用版:https://account.hanatrial.ondemand.com。我创建了帐户和数据库,并将其添加到Eclipse HANA工具中。我该如何检索我必须在HDB_URL位置使用的url/servername/ipaddress

我使用了这个来连接HANA云系统http://saphanatutorial.com/add-sap-hana-cloud-system-in-hana-studio-or-eclipse

我正在尝试做这个http://saphanatutorial.com/sap-hana-text-analysis-using-twitter-data/

package com.saphana.startupfocus.util;

import java.sql.*;
import com.saphana.startupfocus.config.Configurations;

public class HDBConnection {
public static Connection connection = null;

public static Connection getConnection() {
    try {
        if(null == connection){
            connection = DriverManager.getConnection(Configurations.HDB_URL,
                    Configurations.HDB_USER, Configurations.HDB_PWD);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return connection;
}

// Test HDB Connection 
public static void main(String[] argv) throws ClassNotFoundException {
    
    connection = HDBConnection.getConnection();
    if (connection != null) {
        try {
            System.out.println("Connection to HANA successful!");

            Statement stmt = connection.createStatement();
            ResultSet resultSet = stmt
                    .executeQuery("Select 'helloworld' from dummy");
            resultSet.next();
            String hello = resultSet.getString(1);
            System.out.println(hello);

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

你尝试过使用与Eclipse连接相同的URL吗? - Mike Gardner
com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: 无法连接到jdbc:sap://hana.ondemand.com:30015/ [无法连接到主机hana.ondemand.com:30015 [连接超时:connect],-813.]。 - user4542931
http://stackoverflow.com/questions/19527109/trouble-connecting-to-a-remote-hana-database-via-jdbc - user4542931
我真希望能问问那个叫Davidson的家伙是怎么做到的。但是我声望不够,无法提问。 - user4542931
不确定您认为需要多高的声誉才能问别人……为什么不直接去做呢? - Lars Br.
不行,我不能评论。我使用了答案部分来表达我的问题。然而,目前还没有回应。 - user4542931
4个回答

4

如果您尝试连接到SAP HANA云实例,不能直接通过URL连接到该实例。 相反,您需要使用“数据库隧道”,如SAP HANA云文档中所述。

在SAP HANA Studio中,这不是必需的,因为SAP HANA Studio在连接到云系统时会自动处理数据库隧道。


2

1
你可以下载SAP HANA SDK,并使用其中包含的neo工具建立与试用实例的隧道连接:
neo open-db-tunnel 
   -h hanatrial.ondemand.com 
   -i <dbinstance> -a <p-accounttrial> -u <pusername>

这将会给你类似于这样的东西:
SAP HANA Cloud Platform Console Client

Password for your user:

Opening tunnel...

Tunnel opened.

Use these properties to connect to your schema:
  Host name        : localhost
  Database type    : HANAMDC
  JDBC Url         : jdbc:sap://localhost:30015/
  Instance number  : 00

Use any valid database user for the tunnel.
This tunnel will close automatically in 24 hours or when you close the shell.
Press ENTER to close the tunnel now.

现在您可以通过本地隧道连接到端口30015上的云数据库,并使用指定的JDBC URL。

0

如果您正在使用试用/生产SAP云平台帐户,则现在更好的方法是通过使用服务通道来完成。

您需要安装SAP Cloud连接器并创建服务通道。要这样做,请打开Cloud Connector,转到“On-premise to Cloud”选项,并选择HANA数据库选项。完成此操作后,您可以使用localhost作为主机名(因为它通过云连接器路由),端口将由相同的提供。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接