Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Connect to the SAP HANA database using ABAP (ADBC) and Java (JDBC)

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Maintain a record in the table DBCON that points to the HANA database. Enter the hostname and port number of the HANA database in the 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 =' Sap12345'.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 ABAP code to create a new table, insert three entry, and then read it. 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)'). 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 I 042416 TESTPROCraft 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' TESTPROCraft 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 INTO result_line. The implementation of WRITE:/ 'Key:', result_line-key,' Value:', result_line-value.ENDLOOP. Java is similar: public static void main (String [] args) {try {Class.forName ("com.sap.db.jdbc.Driver"); System.out.println ("Create a connection...") Con = (com.sap.db.jdbc.trace.Connection) DriverManager .getConnection ("jdbc:sap://:30015", / /, "system", "enter login password here"); cs = (com.sap.db.jdbc.trace.CallableStatement) con.prepareCall ("call I042416_two_par (NULL, NULL)"); cs.execute () Int index = 0; do {int rowCount = 0; com.sap.db.jdbc.trace.ResultSet rs = (com.sap.db.jdbc.trace.ResultSet) cs.getResultSet (); ResultSetMetaData metaData = rs.getMetaData (); int columnCount = metaData.getColumnCount (); while (rs! = null & & rs.next ()) {for (int I = 1; I

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report