Reputation:
I am trying to connect my Java program to the HANA database. However, I am unable to do so because I have to connect my program 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();
}
}
}
Upvotes: 3
Views: 11337
Reputation: 10388
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.
Upvotes: 4
Reputation: 1
If you are working with a trial/productive SAP cloud platform account, a better way to do it now would be through using a service channel.
You need to install the SAP Cloud connector and create a service channel. To do so, open cloud connector, go to "On-premise to Cloud" option and select the option for HANA Database. Once this is done, you can use localhost as the hostname (since it is routed through the cloud connector) and the port would be provided by the same.
Upvotes: 0
Reputation: 7722
You can download the SAP HANA SDK and use the included neo
-tool to establish a tunnel-connection to your trial-instance:
neo open-db-tunnel
-h hanatrial.ondemand.com
-i <dbinstance> -a <p-accounttrial> -u <pusername>
This gives you something like this:
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.
Now you can connect to your cloud-database via your local tunnel on port 30015 and use the specified JDBC Url.
Upvotes: 1
Reputation: 133
I had faced the same issue and figured out a solution for that.
Please refer to the following link
HOW to connect to sap hana cloud instance thru jdbc Let me know if you have any questions.
Upvotes: 2