Using ABAP (ADBC) and Java (JDBC) to connect to the SAP HANA database

Source: Internet
Author: User
Tags rowcount

Maintain a record in table Dbcon, pointing to the Hana database. The host name and port number of the Hana database are filled in con_env. such as vmxxxx:30015

Data:ls_new TYPE dbcon.ls_new-con_name = ' HAN '. Ls_new-dbms = ' HDB '. Ls_new-user_name = ' System '. Ls_new-password = ' Sap123 ". Ls_new-con_env = ' vml2018:30015 '.              Call FUNCTION ' dbcon_insert ' exporting Dbcon_workarea = Ls_new EXCEPTIONS dbcon_key_exists          = 1 Secure_store_key_exists = 2 Secure_store_other = 3 OTHERS = 4 .   IF SY-SUBRC = 0. write:/ ' Insert successfully '. ENDIF. Then use the ABAP code to create a new table, insert three entry, read it again, and finally delete Table.TYPES:BEGIN of result_t, key Type I, value type      String, END of result_t.DATA:connection type dbcon-con_name VALUE ' HAN ', stmt_ref type ref to Cl_sql_statement,      Cx_sql_exception type ref to Cx_sql_exception, Lv_text type string, Res_ref type ref to Cl_sql_result_set,      D_ref type ref to DATA, Result_tab type TABLE of result_t, Result_line type result_t, row_cnt type I, Con_ref TYPE ref to Cl_sql_connection.con_ref =Cl_sql_connection=>get_connection (connection). Stmt_ref = Con_ref->create_statement ().   TRY.   Stmt_ref->execute_ddl (' CREATE TABLE i042416_testproc_tab (key INT PRIMARY key, Value NVARCHAR (255)) '.   Stmt_ref->execute_update (' INSERT into I042416_testproc_tab VALUES (1, ' first value ') ').   Stmt_ref->execute_update (' INSERT into I042416_testproc_tab VALUES (2, ' Second value ') ').   Stmt_ref->execute_update (' INSERT into I042416_testproc_tab VALUES (3, ' third value ') ').   Res_ref = Stmt_ref->execute_query (' SELECT * from I042416_testproc_tab ').   GET REFERENCE of Result_tab into D_ref.   Res_ref->set_param_table (D_REF).   row_cnt = Res_ref->next_package (). Stmt_ref->execute_ddl (' DROP TABLE i042416_testproc_tab ').   CATCH cx_sql_exception into Cx_sql_exception.   Lv_text = Cx_sql_exception->get_text (). write:/ ' Error: ', Lv_text. Endtry.   LOOP at Result_tab to Result_line. write:/ ' Key: ', Result_line-key, ' Value: ', Result_line-value. ENdloop.   

Java implementations resemble:

public static void Main (string[] args) {try {class.forname ("Com.sap.db.jdbc.d                    River ");              System.out.println ("Create a Connection ..."); Con = (com.sap.db.jdbc.trace.Connection) drivermanager. getconnection ("Jdbc:sap://

Console print Result: Data can be successfully read from the Hana database through JDBC.

To get more original Jerry's technical articles, please follow the public number "Wang Zixi" or scan the QR code below:

Using ABAP (ADBC) and Java (JDBC) to connect to the SAP HANA database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.