Category:开源
Article From:https://www.cnblogs.com/sap-jerry/p/9061907.html

This article assumes that you have the most basic understanding of JDBC (Java Database Connectivity). You can also compare it with ADBC (ABAP Database Connectivity). Please refer to my blog AD for details.BC and JDBC

This article is divided into two parts. The first part is:

  1. Describes how to create a HANA database instance on SAP Cloud Platform (cloud platform).
  2. Develop a Java application and deploy it to the SAP cloud platform. The Java application is also operating on the JDBC database on the SAP cloud platform using the JDBC operation.

The second part:

Develop a Java application and deploy it in On-Premise system located in Corporate Network. The Java application uses Cloud Connector to access HANA instances on the SAP cloud platform. My previous public numberThe chapter uses the function in the ABAP On-Premise system using the Java+SAP cloud platform +SAP Cloud Connector to introduce how applications deployed on Internet Network to access Corporate NThe service on the On-Premise system in etwork, and the scenario that this article will introduce is the opposite: the Java application deployed on On-Premise access the HANA database of the SAP cloud platform on the Internet Network.

The full source code of the Java application introduced in this article is on my GitHub:

Set the password for the database ID and the System user. The database ID I set up here is hana01, which will be used later.

After successful creation, the status of the database instance is changed to STARTED, and the link of its Development Tools can be added to the favorites, which will be used later.

So far, the HANA database instance on the SAP cloud platform has been available. The next step is to develop the Java program and access it through JDBC.

  • Person.java
    The Person model is defined, which contains only three members of ID, firstName and lastName, as well as the corresponding getter and setter methods, the so-called POJO (Plain Old Java Object). POJO thisA name is used to emphasize that it is an ordinary Java object that does not conform to any particular Java convention or framework, such as EJB.

  • PersonDAO.java
    As the name suggests: DAO – Data Access Object. Connect the HANA database instance through JDBC, create the database table named T_PERSONS, and the logic that inserts data into the table is written in the DAO class.

  • PersistenceWithJDBCServlet.java
    A simple UI implemented by Servlet is used to accept user input and call PersonDAO to send the input to HANA database instance.

JDBCThe acquisition of the database DataSource instance is completed by JNDI, which is passed into the DAO constructor as an input parameter, and all the next JDBC operations are carried out through the DataSource.


The configuration of this DefaultDB is located in web.xml:

Deploy the application to the SAP cloud platform, the application is called jerryjdbc.

At this point, only through the configuration of figure web.xml, Java application can not know which database instance to operate on the SAP cloud platform.
To do this, we need to bind the jerryjdbc application to the HANA database instance hana01 created in the first step. The binding is created through the Data Source bingdings page below:

After successful binding, you can insert a Person record Jerry Wang into the HANA database instance through the simple interface provided by Servlet UI.

Accessing the database instance on the phone can see the newly inserted Jerry Wang.

On-Premise system application connects database instances on Internet Network.

The Java application and HANA database examples introduced above are all located on SAP cloud platform. My previous public address used Java+SAP cloud platform +SAP Cloud Connector to call function in ABAP On-Premise system.The applications deployed on Internet Network how to access services on Corporate Network, now we try to flip the access direction: now I deploy the Java application in Corporate Network, such as SAP, a server on the Chengdu Research Institute’s computer room, allows the Java application to connect to the HANA database instance on the SAP cloud platform.
Again, we need to use Cloud Connector again.


Assign the new database instance jerrydemo to the new Channel:

Create success as below. Pay attention to the generated port number 32215, which will be used later.

Modify the configuration of Java server on the On-Premise system and let it point to the database instance of SAP cloud platform.
JavaThere is no need to make any adjustments to the application code, only to change the Server configuration. Modify the file connection.properties under the Servers folder as follows. The purpose is to connect the Server database connection to Cloud Conn.The Service Channel just configured on ector is connected to the HANA database on SAP cloud platform through Cloud Connector as a bridge.

javax.persistence.jdbc.url: The localhost:32215 that points to is the Service Channel configured on Cloud Connector, which is ID for the HANA database instance I assigned. CurrentscheMa=SYSTEM, meaning that the database tables I create next to JDBC will be allocated to SYSTEM schema next.
javax.persistenc.jdbc.user / password: Fill in the access user name and password of the jerrydemo database instance.


At this point all configuration is completed.
Start the localhost server on the On-Premise system and insert two data:

Open the HANA Development Tool connection on the SAP cloud platform and observe two records that have just been inserted through the Web application that just ran on the On-Premise system from the Schema of SYSTEM, indicating that from On-PremisThe e system has written a successful attempt to write to the SAP cloud platform database.

To get more original technical articles of Jerry, please pay attention to the public number “Wang Zixi” or scan the following two-dimensional code:

Leave a Reply

Your email address will not be published. Required fields are marked *