SAP HANA hostname jdbc driver - jdbc

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.

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.

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.

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.

Related

Setting different "ticketСache" or "keytab" parameters for different hive jdbc

I use DBeaver (windows) to connect to different hive servers (Kerberos Auth)
Connection 1 is
jdbc:hive2://<server_address_1_ip>:<port>/main;AuthMech=1;KrbRealm=some.realm.com;KrbHostFQDN=<server_address_1_ip>;KrbServiceName=hive;KrbAuthType=2;SocketTimeout=0;useTicketCache=true;ticketCache=C:\Users\<my_username>\krb5cc_<tech_user_1>;renewTGT=true;doNotPrompt=true;principal=<tech_user_1>#some.realm.com
Connection 2 is
jdbc:hive2://<server_address_2_ip>:<port>/main;AuthMech=1;KrbRealm=some.realm.com;KrbHostFQDN=<server_address_2_ip>;KrbServiceName=hive;KrbAuthType=2;SocketTimeout=0;useTicketCache=true;ticketCache=C:\Users\<my_username>\krb5cc_<tech_user_2>;renewTGT=true;doNotPrompt=true;principal=<tech_user_2>#some.realm.com
I want to connect to this servers at same time and don't matter how it will be (using "ticketСache" or "keytab" for example)
Now, in order to connect, I need to initialize the ticket (kinit <tech_user_1>/<tech_user_2>), restart the application, but only one of the two connections will be used.
When I don't have valid ticket, DBeaver show error: "Unable to obtain Principal Name for authentication". I think DBeaver ignore some parameters from jdbc connection url.
When I use driver provided by cloudera I see krbJAASFile option in DriverSetting page of DBeaver. You can try the same. My jaas conf looks like below:
Client {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="/Users/raid/hive_jdbc_logs/raid.keytab"
principal="raid#some.realm.COM"
doNotPrompt=true;
};
And url format is:
jdbc:hive2://<server_address_fqdn>:<port>;AuthMech=1;KrbHostFQDN=<server_address_fqdn>;KrbRealm=some.realm.COM;KrbServiceName=hive

establish connection to oracle with Google Apps Script via JDBC

I'm trying to establish the connection to oracle database using Google Apps Script from google sheet by using the sample code below.
But, I keep getting error: Exception: Connection URL uses an unsupported JDBC protocol.
// make the connection
var connection = Jdbc.getConnection("jdbc:oracle://db IP or host name:port number/DB name", "User name", "password");

Can I connect to IBM Db2 Event Store using the standard Db2 Client JAR?

I am trying to connect to an IBM Db2 Event Store cluster from a Java application that is already connecting to a Db2 instance. Can I have the same application connect to the Event Store instance using the same Jar ?
I've found my answer in this github repository containing samples for Db2 Event Store remote applications.
It seems pretty straight forward, like any regular connection to a Db2 instance, but in the case of Db2 Event Store Enterprise Edition, it is configured with SSL out of the box, so there are a few more parameters that are required for the connection to be successful. From that document, these are the steps that I extracted:
First we will need to know the external IP and port to be used for JDBC connections. To do this, login to the master node 1 of the installed Db2 Event Store cluster and run: kubectl get sac -n dsx
Get the EXTERNAL-IP column value for the eventstore-tenant-engine-svc service, and the port number is 18729 from the exported ports (PORT(S) column) that corresponds to the JDBC port.
Download the SSL keystore and password through the REST API using the instructions documented in the IBM Knowledge Center for Db2 Event Store. This is necessary because Db2 Event Store is configured with SSL with a default keystore out of the box (this may change if you configure your own keystore after installation). This is the link to the documentation for REST
Then to establish the connection from your application, in the DriverManager.getConnection invocation, use the IP, Port, the location for the keystore, and the password, jdbc:db2://<Your Db2 Event Store Cluster VIP>:18729/EVENTDB:sslConnection=true;sslTrustStoreLocation=<path to clientkeystore downloaded from cluster>;sslKeyStoreLocation=<path to clientkeystore downloaded from cluster>;sslKeyStorePassword=<password for clientkeystore retrieved from cluster>;sslTrustStorePassword=<password for clientkeystore retrieved from cluster>;securityMechanism=15;pluginName=IBMIAMAuth;. ** Note that this is the JDBC connection URL. The database name EVENTDB is the default database that is created by Db2 Event Store at install time.
If you do not already have it, download the Db2 JDBC client driver from the IBM Data Server Client Packages page under the IBM Support website and store it in your CLASSPATH
// Establish connection with ssl and user credentials
conn =
DriverManager.getConnection(
"jdbc:db2://" + IP + ":18729/EVENTDB:" +
"sslConnection=true;" +
"sslTrustStoreLocation="+ KEYDB_PATH + ";" +
"sslKeyStoreLocation="+ KEYDB_PATH + ";" +
"sslKeyStorePassword="+ KEYDB_PASSWORD + ";" +
"sslTrustStorePassword="+ KEYDB_PASSWORD + ";" +
"securityMechanism=15;" +
"pluginName=IBMIAMAuth;",
USERNAME, PASSWORD);
An alternative to downloading the Keystore and its password is to just download the certificate, also through the REST API using the instructions documented in the IBM Knowledge Center for Db2 Event Store. This is the link to the documentation for REST
Then to establish the connection from your application, in the DriverManager.getConnection invocation, use the IP, Port, the certificate file location, jdbc:db2://<Your Db2 Event Store Cluster VIP>:18729/EVENTDB:sslConnection=true;sslCertLocation=<path to certificate downloaded from cluster>;securityMechanism=15;pluginName=IBMIAMAuth;. ** Note that this is the JDBC connection URL. The database name EVENTDB is the default database that is created by Db2 Event Store at install time.
// Establish connection with ssl and user credentials
conn =
DriverManager.getConnection(
"jdbc:db2://" + IP + ":18729/EVENTDB:" +
"sslConnection=true;" +
"sslCertLocation="+ CERT_PATH + ";" +
"securityMechanism=15;" +
"pluginName=IBMIAMAuth;",
USERNAME, PASSWORD);

How to connect to on-premise Oracle-db using Azure Functions?

I'm trying to create an Azure Function to connect and query an on-premise Oracle-DB. I can not see that the Oracle Client or an ODBC-driver is installed on the servers to handle this.
Are there any solutions to this using JS or Python?
I have tried using the node-odbc driver, but the server is missing the Oracle client.
Partially answer for connecting to on-premise service like Oracle-db from Azure Functions, there is an existing SO thread How to Azure function configure for Site-to-Site Connectivity? had answered it, which you can refer to. So first, you must make sure networking access to on-premise server available.
Then, if you want to query oracle database via odbc, the oracle odbc driver must be installed on the client-side. However, the oracle odbc driver is a commerce componet, which you need to pay for getting it, and install it manually in Azure Functions. So even you want to use JS or Python to connect it, I think using Java with Oracle jdbc driver is a better solution from Azure Functions to connect Oracle DB to avoid the additional installation.
The other way I thought is to deploy a REST API app as proxy on your on-premise server to handle the query request from Azure Functions with JS or Python to help connecting Oracle DB.
Create and deploy your code to Azure Functions as a custom Docker container using a Linux base image. Install the Oracle client libraries in custom image. Check out my blog on the topic:
https://www.ravitella.com/azure-function-container/
You will need to establish a hybrid connection. see https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections
Then you can refer to this thread to establish a context:
https://social.msdn.microsoft.com/Forums/en-US/2434fe10-3219-4625-bdbf-b9e96421230b/entity-framework-with-oracle-and-sql
For a nodejs solution, I would add the NPM and install it using Kudu using node-oracledb:
https://oracle.github.io/node-oracledb/doc/api.html#getstarted
// myscript.js
// This example uses Node 8's async/await syntax.
var oracledb = require('oracledb');
var mypw = ... // set mypw to the hr schema password
async function run() {
let connection;
try {
connection = await oracledb.getConnection( {
user : "hr",
password : mypw,
connectString : "localhost/XEPDB1"
});
let result = await connection.execute(
`SELECT manager_id, department_id, department_name
FROM departments
WHERE manager_id = :id`,
[103], // bind value for :id
);
console.log(result.rows);
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
run();
sample code

Connect to SQL Server using Windows Authentication with different user account in JDBC

I need to connect to SQL Server using Windows Authentication with different user account in JDBC. This is the code I am using:
static final String DB_URL = "jdbc:sqlserver://IP:port; databaseName=xyz; integratedSecurity=false; domain=abc";
Connection con = DriverManager.getConnection(DB_URL,USER,PASS);
And here is the Error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'abcd'
Like described in question given by #konstantin-v-salikhov you need to set integratedSecurity=true if you actually want to use Integrated Authentication (and in that case it will autenticate as the user running the application). You also need the sqljdbc_auth.dll file to be installed. When you make the actual call you shouldn't provide any username or password, just do something like this:
Properties info = new Properties();
Connection con = DriverManager.getConnection(DB_URL, info);
If you want to use SQL Server authentication (like you are doing in your code sample) you need to enable mixed mode authentication for your SQL Server instance.

Resources