我正在尝试将我的 Java 程序连接到 HANA 数据库。但是,我无法这样做,因为我必须通过一个我不知道的 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();
}
}
}
由于您尝试连接到 SAP HANA 云实例,因此您不能通过 URL 直接连接到该实例。 相反,您需要使用“数据库隧道”,如 SAP HANA Cloud 文档中所述。
在 SAP HANA Studio 中,这不是必需的,因为 SAP HANA Studio 会在连接到云系统时自动为您处理数据库隧道。
您可以下载 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。
如果您使用的是试用/高效 SAP 云平台帐户,现在更好的方法是使用服务渠道。
您需要安装 SAP Cloud 连接器并创建服务通道。为此,打开云连接器,转到“本地到云”选项,然后选择 HANA 数据库选项。一旦完成,您可以使用 localhost 作为主机名(因为它是通过云连接器路由的)并且端口将由相同的提供。