If you want your Java application to consume SAP HANA Database (for example, to use an HDI container), follow the steps below.
-
Create a service instance for the HDI container, using the
cf create-servicecommand.cf create-service hana hdi-shared my-hdi-container -
Bind the service instance to a Java application.
Specify the service instance in the Java application's deployment manifest.yml file.
services: - my-hdi-container -
Add a resource reference XML block. Its technical name must be the same as the name of the service instance.
<resource-ref> <res-ref-name>jdbc/my-hdi-container</res-ref-name> <res-type>javax.sql.DataSource</res-type> </resource-ref>Add this resource reference to the following files, respectively:
-
For Tomcat:
web.xmlandcontext.xml -
For TomEE:
web.xmlandresource.xml
-
-
Look up the data source in your code.
You can find the reference to the data source in two ways – by using annotations or with JNDI look-up. Add the relevant code to your Java servlet:
-
Annotations
@Resource(name = "jdbc/my-hdi-container") private DataSource ds; -
Java Naming and Directory Interface (JNDI) look-up
Context ctx = new InitialContext(); return (DataSource) ctx.lookup("java:comp/env/jdbc/my-hdi-container");
-
Related Information