SAP ABAP ADBC和Java JDBC的使用比较
Horst Keller has already introduced ADBC in his blog ABAP Geek 15 – ADBC long times ago. And recently during my self study on PostgreSQL I made some practice to connect PostgreSQL in Java programming using Java Database Connectivity – JDBC. In fact I found out that there are lots of commonality between these two technologies.
There is a demo program demo_adbc_query mentioned in SAP help to demonstrate the use of ADBC.
I make some changes on it in order to perform a line-by-line comparison with JDBC.
The source code of adapted program:
And now have a look at how JDBC can achieve the same.
I have replicated an ABAP table COMM_PRODUCT to my local PostgreSQL server:
And I manually inserted two test records into it:
Both is the source code implemented in Java to perform a query against this table and display result:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; public class PostgreSQLJDBC {private Connection connection = null;private void select() {try {int index = 0;Class.forName("org.postgresql.Driver");connection = DriverManager.getConnection("jdbc:postgresql://localhost:9812/zproduct", "postgres", "XXXXXX");Statement stmt = connection.createStatement();String query = "SELECT * FROM public.comm_product;";ResultSet rs = stmt.executeQuery(query);while ( rs.next() ) {System.out.println("Row index: " + index++);String client = rs.getString("client");System.out.println("Client: " + client);String guid = rs.getString("product_guid");System.out.println("Product guid: " + guid);Timestamp validFrom = rs.getTimestamp("valid_from");System.out.println("Valid from: " + validFrom);}rs.close();stmt.close();connection.close();} catch (Exception e) {e.printStackTrace();} }public static void main(String args[]) {PostgreSQLJDBC jdbcTest = new PostgreSQLJDBC();jdbcTest.select();} }Output in console:
And I mark the corresponding part in both language which has the same semantic meaning with same color ( although grammar is different ).
Through this comparison we can know that both connectivity technology follow the same idea.
Further reading
I have written a series of blogs which compare the language feature among ABAP, JavaScript and Java. You can find a list of them below:
- Lazy Loading, Singleton and Bridge design pattern in JavaScript and in ABAP
- Functional programming – Simulate Curry in ABAP
- Functional Programming – Try Reduce in JavaScript and in ABAP
- Simulate Mockito in ABAP
- A simulation of Java Spring dependency injection annotation @Inject in ABAP
- Singleton bypass – ABAP and Java
- Weak reference in ABAP and Java
- Fibonacci Sequence in ES5, ES6 and ABAP
- Java byte code and ABAP Load
- How to write a correct program rejected by compiler: Exception handling in Java and in ABAP
- An small example to learn Garbage collection in Java and in ABAP
- String Template in ABAP, ES6, Angular and React
- Try to access static private attribute via ABAP RTTI and Java Reflection
- Local class in ABAP, Java and JavaScript
- Integer in ABAP, Java and JavaScript
- Covariance in Java and simulation in ABAP
- Various Proxy Design Pattern implementation variants in Java and ABAP
- Tag(Marker) Interface in ABAP and Java
- Bitwise operation ( OR, AND, XOR ) on ABAP Integer
- ABAP ICF handler and Java Servlet
- ADBC and JDBC
- CL_ABAP_CORRESPONDING, CL_JAVA_CORRESPONDING and CL_JS_CORRESPONDING
- Build an Cross Site Scripting example in Java and ABAP
- Play around with JSONP in nodeJS server and ABAP server
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的SAP ABAP ADBC和Java JDBC的使用比较的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 哈罗单车怎么远程锁车
- 下一篇: 航海王燃烧意志豹子怎么过