In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "how to use JDBC to operate the HANA database on the SAP cloud platform". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use JDBC to operate HANA database on SAP cloud platform.
Create a HANA database instance on the SAP cloud platform
Log in to SAP cloud platform Cockpit and create a new HANA database instance:
Set the password for the databases ID and System user. Here I set the database ID to hana01, which will be used later.
After the database instance is successfully created, the status of the database instance changes to STARTED, and the link to its Development Tools can be added to your favorites, which will be used later.
At this point, the HANA database instance on the SAP cloud platform is available. The next step is to develop a Java program to access it through JDBC.
Using JDBC to access HANA database
Import the Java application on my github to Eclipse, as shown in the following figure:
The application is mainly divided into three files:
Person.java
The Person model is defined, which contains only three members: id,firstName and lastName, and the corresponding getter and setter methods, that is, the so-called POJO (Plain Old Java Object). The name POJO is used to emphasize that it is a normal Java object that does not follow any particular Java convention or framework (such as EJB).
PersonDAO.java
As the name implies: DAO-Data Access Object. Connect to the HANA database instance through JDBC and create a database table called T_PERSONS. The logic for inserting data into the table is written in this DAO class.
PersistenceWithJDBCServlet.java
A simple UI implemented through Servlet to accept user input and call PersonDAO to send the input to the HANA database instance.
The acquisition of the JDBC database DataSource instance is done through JNDI, which is passed as an input parameter to the DAO constructor, and all subsequent JDBC operations are done through this DataSource.
The successful creation is shown in the following figure. Note that the generated port number is 32215, which will be used later.
Modify the configuration of Java server on the On-Premise system to point to the database instance of the SAP cloud platform
The code for the Java application does not need to be adjusted, only the Server configuration needs to be changed. Modify the file connection.properties under the Servers folder. The details are as follows. The purpose is to connect the database of the Server to the Service Channel just configured on the Cloud Connector, and use Cloud Connector as a bridge to connect to the HANA database on the SAP cloud platform.
Javax.persistence.jdbc.url: the localhost:32215 you point to is the Service Channel configured on Cloud Connector, and the ID of the HANA database instance I assigned to this Channel is jerrydemo. Currentschema=SYSTEM, which means that the next database table I created through JDBC will be assigned to SYSTEM schema.
Javax.persistenc.jdbc.user / password: enter the access username and password of the database instance jerrydemo.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.