cancel
Showing results for 
Search instead for 
Did you mean: 

Connect to SAP HANA Database with JDBC

Former Member
0 Kudos

Hello,

I am trying to connect to SAP HANA Database with JDBC.

I tried the example in the following Picture.

But it doesnt work.

As Server Name i took the sap hana cloud platform Server Name.

I named it "myserver".

Is the username my email? And the Passwort my account Passwort?

Sorry for my bad english, im from Germany.

Best regards!

And tank you for your help!

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

And i have another question. Do you know where i can read something about the sap hana xs application?

I mean i know how to create one. but i dont know for what exactly i Need one?

do i Need one to run a Java application in the cloud?

best regards,

aylin

pfefferf
Active Contributor
0 Kudos

Nope, a XS (classic) application is written in JavaScript. It is a different model you can use on HANA which has no relation to your Java application.

Former Member
0 Kudos

Someone told me that i dont use one of them when the application runs in the cloud?

I tried it with the "persistence with jdbc example" now and it works.

But where can i find the database i create in this example?

Thank you for your help!

Best regards,

Aylin

pfefferf
Active Contributor
0 Kudos

Right, if the application is running in the cloud itself you don't need the "connectors". Thought you would run it on-premise.

For your case you can check Adding Persistence with JDBC. As described in the example you have to define a resource reference in the web.xml. To define the db/schema which should be used to have to do the data source binding. It can be done for example in the Cloud Cockpit (go to your deployed Java application, select it and do the binding in menu "Data Source Bindings").

Regards,

Florian

Former Member
0 Kudos

If the application is running in the cloud how would the example in my first question work? what Server Name could i specify?

I just copied the resource reference from the example because i didnt understand the meaning.

Did i understand it right, that i have to create a db/Schema and then write it in the resource reference? like this: ... <res-ref-Name>mySchma</res-ref-Name> and which type?

Best regards and thank you very much,

Aylin

pfefferf
Active Contributor
0 Kudos

All topics are described in the provided link.

In the web.xml a resource reference has to be described like following:


<resource-ref>

  <res-ref-name>jdbc/DefaultDB</res-ref-name>

  <res-type>javax.sql.DataSource</res-type>

</resource-ref>

The connection is then established via a "javax.sql.DataSource" object.


InitialContext ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/DefaultDB");

Please simply read the example, then you will understand the process.

Former Member
0 Kudos

Thank you!

if i want to establish the Connection with jdbc in the cloud,

what is the host Name i have to use?

Best regards,

Aylin

pfefferf
Active Contributor
0 Kudos

If you still haven't recognized it, that is the way how you establish a JDBC connection in the cloud. You do not define a host name directly in your coding. The database is bound via the resource binding to the application.

Instead of asking several times the same question you should read through the documentation to get the understanding.

Former Member
0 Kudos

i didnt found it in the documentation.

you gave me the link "adding persistence with jdbc" i have read before but i did not read this Information in it.

this is the documentation you mean, isnt it?

maybe its because of my bad english... i dont know and im sorry for this.

thank you for answering my questions.

pfefferf
Active Contributor
0 Kudos

Are you using a Cloud Connector service channel or a database tunnel to connect from the on-premise side to the HANA system in HCP?