在表DBCON里維護一條記錄,指向HANA數(shù)據(jù)庫。con_ENV里填入HANA數(shù)據(jù)庫的主機名和端口號。如vmXXXX:30015
成都創(chuàng)新互聯(lián)公司專注于興安網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供興安營銷型網(wǎng)站建設,興安網(wǎng)站制作、興安網(wǎng)頁設計、興安網(wǎng)站官網(wǎng)定制、微信小程序服務,打造興安網(wǎng)絡公司原創(chuàng)品牌,更為您提供興安網(wǎng)站排名全網(wǎng)營銷落地服務。
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. 然后使用ABAP代碼創(chuàng)建一個新的table,插入三條entry進行,再讀出來,最后刪除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 INTO result_line. WRITE:/ 'Key:' , result_line-key, ' Value:', result_line-value. ENDLOOP.
Java實現(xiàn)類似:
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", "此處填入登錄密碼"); 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 <= columnCount; i++) { System.out.print(rs.getString(i) + " "); if (i == columnCount) { System.out.println(); } } System.out.println("Current Result Set Index:" + index + " Row Count: " + rowCount++); } System.out.println("Result Set Index: " + index++); } while(cs.getMoreResults()); }
console打印結果:數(shù)據(jù)能夠成功通過JDBC從HANA數(shù)據(jù)庫讀取出來。
要獲取更多Jerry的原創(chuàng)技術文章,請關注公眾號"汪子熙"或者掃描下面二維碼:
當前名稱:使用ABAP(ADBC)和Java(JDBC)連接SAPHANA數(shù)據(jù)庫
文章路徑:http://jinyejixie.com/article34/poeose.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、軟件開發(fā)、網(wǎng)站維護、網(wǎng)站內(nèi)鏈、全網(wǎng)營銷推廣、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)