Java Web Series: JDBC Foundation

ADO. Net in Java is the enterprise library dataaccessapplicationblock module, the module in Java, and the orm of entityframework in Java. The concepts of relational database, SQL, database transaction and distributed transaction are universal.

1.JDBC

JDBC code and ADO Net code, except that you write a demo to master the core object during learning, it is not suitable for direct use in the project. In addition, the ever-changing academic abstract interface in Java has brought great inconvenience to most containers and frameworks I have seen so far. For example, some abstract types defined in Tomcat and spring are different from each other in terms of attributes and methods Net, but it has to adapt to the basic interface in Java. Abstraction cannot only focus on the operation interface rather than the basic data structure as in Java. The abstraction of the correct type is more important than the abstraction of the method, but there seems to be another principle of abstraction in Java, that is, being different, not just focusing on the operation.

(1) Core object

ADO. Net, DataAdapter and dataset are built on the core objects.

JDBC has four core interfaces,,, and. Is a subtype of statement.

Although the two cannot match completely, the core operations of database operations are the same, which are the process of opening links, sending commands and closing connections.

(2) Parameter processing

The core of parameters is index and parameter value. ADO. Net provides the abstraction of types for parameters. Abstract types of parameters are not provided in JDBC. Instead, parameters are set through defined methods. Objects of this type can be obtained through connection objects.

(3) Transaction processing

The core operations of a transaction are commit and rollback. ADO. Net provides the abstraction of types for transactions. You can open explicit transactions through the begintransaction method of dbconnection JDBC does not provide the abstract type of transaction, but operates the transaction through the defined,, and methods. The automatic submission of implicit transactions is consistent with the manual control of explicit transactions.

(4) Data source

Connection in JDBC does not have advanced functions such as connection pool. The data source interface is defined for advanced functions such as connection management, connection pool and distributed transactions. The importance of connection pool is not emphasized. We can use third-party datasource implementations such as Apache commons DBCP 2 or c3p0 (hibernate). The spring framework also has some built-in simple datasource implementations, such as simpledriverdatasource, singleconnectiondatasource, drivermanagerdatasource, etc.

We use drivermanager, commons dbcp2 (reference 1), c3p0 (reference 2) and h2database (reference 3) to demonstrate the use of connectionless pool, dbcp2 connection pool and c3p0 connection pool respectively:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>