I am trying to connect my java programme to the hana database. However, I am unable to do so because I have to connect my programme to the database through a url which I don't know. I registered for a hana trial online: https://account.hanatrial.ondemand.com. I created the account and the database and added it to the eclipse hana tools. How do I retrieve the url/servername/ipaddress that I have to use in place of HDB_URL
I used this to connect the hana cloud system http://saphanatutorial.com/add-sap-hana-cloud-system-in-hana-studio-or-eclipse
And I am trying to do this 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();
}
}
}
}
Since you try to connect to a SAP HANA cloud instance, you cannot directly connect via an URL to the instance. Instead, you need to use a "Database Tunnel" as explained in the documentation for SAP HANA Cloud.
In SAP HANA Studio this is not required, because SAP HANA Studio automatically handles the database tunnel for you, when connecting to a cloud system.