我正在尝试将我的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();
}
}
}