"JDBC History" from JDBC1.0 to JDBC4.0

Source: Internet
Author: User
Tags connection pooling instance method java se

JDBC is a JAVAAPI (applicationprogramminginterface application design interface) that can be used to execute SQL statements. It consists of classes and interfaces written in some Java languages. JDBC provides a standard application design interface for database application developers, database foreground tool developers, and enables developers to write complete database applications in a pure Java language.

This article describes the history of jdbc1.0--jdbc4.0, with a small amount of programming.


I. The evolution of ODBC to JDBCwhen it comes to JDBC, it's easy to associate another very familiar word, "ODBC." Are there any links between them? If so, what is the relationship between them?

ODBC is a shorthand for opendatabaseconnectivity in English. It is a standard application data interface implemented in C language for accessing data in related or unrelated database management systems (DBMS). With ODBCAPI, applications can access data stored in a variety of different database management systems (DBMS), regardless of the data storage format and programming interface used by each DBMS.
structure Model of ODBCThe structure of ODBC consists of four main parts: The application interface, the drive manager, the database drive, and the data source.

application Interface : Masks the differences between function calls between different ODBC database drives and provides users with a unified SQL programming interface.
Drive Manager : Mount the database drive for your application.
Database Drive : A function call that implements ODBC to provide SQL requests to a specific data source. If required, the database drive modifies the application's request so that the request conforms to the grammar supported by the relevant DBMS.
Data Source : The data that the user wants to access and the operating system associated with it, the DBMS, and the network platform used to access the DBMS.

Although the primary purpose of the ODBC drive Manager is to load the database drive for ODBC function calls, the database drive itself also performs ODBC function calls and mates with the database. Therefore, when an application makes a call to connect to the data source, the database drive can manage the communication protocol. When a connection to a data source is established, the database drive can handle requests made by the application system to the DBMS, perform necessary translations of the analysis or design from the data source, and return the results to the application system.
the birth of JDBC

Since the Java language was officially published in May 1995, Java has swept the world. There are a large number of programs written in the Java language, including database applications. Since there is no Java-language API, programmers have to add C-language ODBC function calls to Java programs. This makes a lot of Java's outstanding features can not be fully played, such as platform-independent, object-oriented features and so on. As more and more programmers are becoming more and more interested in the Java language, more and more companies are devoting more and more effort to the development of Java programming, and the requirement of accessing database API for Java language interface becomes more and more strong. Because of the shortcomings of ODBC, such as it is not easy to use, no object-oriented features and so on, Sun decided to develop a Java language for the interface of the database application development interface. In the jdk1.x version, JDBC is an optional part, and when JDK1.1 is published, the SQL class package (that is, JDBCAPI) becomes the standard part of the Java language.



two. JDBC 1.0

JDBC 1.0 is published with JDK1.1, and the JDBC operation-related interfaces and classes are located in the java.sql in the package.




Third, JDBC 2.0The DBC 2.0 API is divided into two parts: the Core API and the extension API.
Core API (java.sql package)As a general rule, the new features of the JDBC Core API work in two ways. One is to support some new features, and the other is to support the new SQL data type.
1, in support of new features: Including the result set can be scrolled backward, batch update data. In addition, a character stream operation is provided for the Unicode character set.
2. In terms of data types that support sql: The newly added blob, CLOB, and array interfaces can be data types that are large chunks of application operations,
Extension API(javax.sql bag)

1 DataSource Interface: A data source interface that works with the Java Name Directory Service (JNDI).

        JDBC1.0 is the original use of the DriverManager class to generate a connection to the data source. JDBC2.0 in an alternative way, using DataSource implementations, the code becomes more compact and more manageable.
A DataSource object represents a true data source. Depending on how the DataSource is implemented, the data source can be either from a relational database, a spreadsheet, or a file in tabular form. When a DataSource object is registered in the moniker service, the application can obtain the DataSource object through the name service and use it to generate a connection to the data source represented by the datasource.
Information about the data source and how to locate the data source, such as the name of the database server, on which machine, the port number, and so on, are included in the properties of the DataSource object. In this way, it is more convenient for the design of the application, because there is no need to write the driver's name into the program. The
is configured by the system administrator or by someone with the appropriate permissions to configure the DataSource object. Configure the DataSource, including setting the properties of the DataSource, and then Register to the Jndi name service to . During the process of registering the DataSource object, the system administrator needs to associate the DataSource object with a logical name. A name can be arbitrary, usually taken as a name that can represent a data source and is easy to remember. In the following example, the full name of the logical name is: Jdbc/inventorydb.
Once the data source object is configured, the Application designer can use it to generate a connection to the data source. The following code snippet provides an example of how to get a data source object in a Jndi context, and then how to use the data source object to generate a connection to the data source. The first two lines use the Jndi API, the third line is the JDBC API:
 

====== code 3.1========context CTX = new InitialContext (); DataSource ds = (DataSource) ctx.lookup ("Jdbc/inventorydb"); Connection con = ds.getconnection ("MyPassword", "MyUserName");

In a basic datasource implementation, The connection object returned by the Datasource.getconnection method is the same as the connection object returned by the Drivermanager.getconnection method . Because of the convenience provided by DataSource, we recommend using DataSource objects to get a connection object


2, Connection pooling (connection pool):

Instead of using a new connection for each request, you can reuse the connection.

The Getconnection method of the DataSource object returns whether the connection in a connection pool is entirely dependent on the implementation of the DataSource object . If the DataSource object implementation works with a server that supports the middle tier of a connection pool, the DataSource object automatically returns the connection in the connection pool, which can also be reused.


3. Distrubute transaction (Distributed Transaction): Multiple database servers are involved in a transaction.

Getting a connection to support a distributed transaction is similar to getting a connection in a connection pool. Again, the difference is in the implementation of the DataSource, not the way in which the application gets connected.


4, Rowsets:

Rowset are implemented on top of the drive, and can be implemented by anyone else .

Any type of rowset implements the rowset interface, and the rowset interface expands the ResultSet interface. This way the rowset object has all the functions of the ResultSet object.

We are more interested in the new functionality provided by the rowset interface. As a JavaBean component, the rowset object can add or remove a listener (listener), can get or set its property values, one of these attributes is a string representing a request to the database query, the rowset interface defines the method of setting parameters , and also provides a way to execute the request. This means that the rowset object is able to execute a query request and can be evaluated based on the result set it produces. Similarly, rowset can be computed from any tabular data source, so it is not limited to relational databases.

SummaryThe JDBC2.0 standard extension API expands JDBC technology into a completely new concept by registering with DataSource on the Jndi name service. Make your application's code more sophisticated and easy to control. The new API supports connection pooling and supports distributed transactions. Finally, it also allows the Java application to propagate the result set on the network, and it is not possible to scroll the resultset into a scrollable rowset.



iv. JDBC 3.0

"MORE: http://www.ibm.com/developerworks/cn/java/j-jdbcnew/"

JDBC3.0 with JDK1.4, let's look at its features!

Meta Data API

The DatabaseMetaData interface can retrieve a hierarchy of SQL types, and a new Parametermetadata interface can describe the types and properties of parameters in PreparedStatement objects.

named parameters in the Callablestatementsbefore JDBC 3.0, set a parameter in a stored procedure to specify its index value instead of its name. The CallableStatement interface has been updated, and you can now specify the parameters by name. changes in data typesSeveral changes have been made to the data types supported by JDBC, one of which is the addition of two new data types.
the two new data types that are added are Java.sql.Types.DATALINK and Java.sql.Types.BOOLEAN . DATALINK provides access to external resources or URLs, and the BOOLEAN type is logically equivalent to the BIT type, but adds semantic meaning. The DATALINK column value is retrieved from an instance of ResultSet by using the new GetURL () method, and the BOOLEAN type is retrieved by using Getboolean ().

Retrieving auto-generated keywordsto solve the need to get the values of automatically generated or automatically added keywords, the JDBC 3.0 API will now get this value easily. To determine the value of any resulting keyword, simply specify an optional tag in the Execute () method of the statement to indicate that you are interested in getting the resulting value. You may be interested in Statement.return_generated_keys or Statement.no_generated_keys. After executing this statement, the value of the resulting keyword is obtained by retrieving the ResultSet from the Statement instance method Getgeneratedkeys (). The ResultSet contains the columns for each of the generated keywords. As follows:

Statement stmt = conn.createstatement () stmt.executeupdate ("INSERT into authors" +           ' (first_name, last_name) "+           "VALUES (' George ', ' Orwell ')",           Statement.return_generated_keys); ResultSet rs = Stmt.getgeneratedkeys (); if (Rs.next ()) {    //Retrieve the auto generated key (s).    int key = Rs.getint ();}

Connector RelationshipsThe Java EE linker architecture Specifies a set of protocols that allow an enterprise's information system to be connected to an application server in an pluggable manner. This architecture defines the resource adapters that are responsible for connecting to external systems. The Connector Service Provider interface (the Connectors service Provider INTERFACE,SPI) coincides closely with the services provided by the JDBC interface.
The JDBC API implements two of the three Protocols defined by the linker architecture. The first is the connection management that connects the application component to the backend system, which is implemented by the DataSource and ConnectionPoolDataSource interfaces. The second is transaction management that supports transactional access to resources, which is handled by Xadatasource. The third is security management that supports secure access to back-end systems, where the JDBC specification does not have any corresponding points. The JDBC interface can still be mapped to the connector SPI, despite the last shortcoming. If a driver vendor maps its JDBC driver to a connector system protocol, it can deploy its driver as a resource adapter and immediately enjoy the benefits of pluggable, encapsulated, and deployed in the application server. In this way, a standard API can be used by enterprise developers in different kinds of enterprise information systems.
ResultSet to maintain sex

A cursor (or result) that can be persisted, meaning that the cursor will not automatically close after the transaction containing it is committed. JDBC 3.0 adds support for specifying cursor persistence. To develop your ResultSet retention, you must do so when you are ready to write a statement using the Createstatement (), preparestatement (), or Preparecall () methods.

In general, closing cursor operations after a transaction is committed can result in better performance. Unless you need the cursor after the end of the transaction, you might want to close it after the commit operation is performed. Because the specification does not stipulate the ResultSet of the default, the specific behavior will also depend on the performance. However, I hope that when the JDBC 3.0 driver is available, most executions will still close the cursor after the end of the transaction.

return multiple resultsOne limitation of the JDBC 2 specification is that statements that return multiple results can only open one ResultSet at any given time. As part of the change in the JDBC 3.0 specification, the specification allows the Statement interface to support multiple open resultsets. However, it is important that the execute () method still closes any ResultSet that were opened in the previous execute () call. Therefore, to support multiple open results, the Statement interface will add an overloaded Getmoreresults () method. The new method makes an integer tag that specifies the behavior of the previous open ResultSet when the Getresultset () method is invoked.

Connection PoolJDBC 3.0 defines several standard connection pool properties. Developers do not need to directly modify these attributes with the API, but rather through application servers or data storage devices. Since developers are only indirectly affected by the normalization of connection pool properties, the benefits are not obvious. However, by reducing the number of properties for vendor-specific settings and replacing them with standardized attributes, developers can more easily swap between different vendors ' JDBC drivers. In addition, these attributes allow the administrator to optimize the connection pool to maximize the performance characteristics of the application.

Prep Statement PoolIn addition to improved support for connection pooling, it is now possible to buffer prepared statements. The PREP statement allows you to precompile it with a common SQL statement, which greatly improves performance when the statement is executed more than once. On the other side, building a PreparedStatement object can bring a certain amount of overhead. So, ideally, the life cycle of this statement should be long enough to compensate for the overhead it brings. Developers who pursue performance sometimes want to distort their object model in order to extend the life cycle of PreparedStatement objects. JDBC 3.0 is no longer a concern for developers because the data source layer is now responsible for caching prepared statements. statement is no different from normal JDBC 2 code. This is because the buffer of the statement is fully implemented internally . This means that under JDBC 3.0, your existing code can automatically take advantage of the statement pool.



Five. JDBC 4.0"MORE: https://www.ibm.com/developerworks/cn/java/j-lo-jse65/"databases in Java Db:java 6newly installed JDK 6 will probably find that in addition to the traditional bin, JRE and other directories, JDK 6 has a new directory named DB. This is the new member of Java 6: Java DB. This is a pure Java implementation, open source database management system (DBMS), originating from the Apache Software Foundation (ASF) name of the project Derby. It's only 2MB in size.
Auto Load DriverThe internal implementation mechanism of Java.sql.DriverManager determines the appearance of such code. Only through Class.forName to find a specific driver Class file, the Drivermanager.getconnection method can successfully get Java application and database connection. This code adds an unnecessary burden to the programmer, and the JDK developer is aware of that. Starting with Java 6, the application no longer needs to load the driver explicitly, and DriverManager started to be able to assume the task automatically.
RowIdPeople familiar with large DBMS such as DB2 and Oracle must not be unfamiliar with the concept of ROWID: It is a "hidden" column in a data table, a unique identifier for each row, indicating the physical or logical location of the line. Due to the widespread use of the ROWID type, the JAVA.SQL.ROWID data type is added to Java SE 6, allowing the JDBC program to access the ROWID types in SQL. Admittedly, not all DBMS support the ROWID type. Even with support, different ROWID have different life cycles. Therefore, it is a good practice to use databasemetadata.getrowidlifetime to judge the life cycle of a type.
SQLXMLThe sql:2003 Standard introduces Sql/xml as an extension of the SQL standard. Sql/xml defines how the SQL language interacts with XML: How to create XML data, how to embed an XQuery expression in an SQL statement, and so on. As part of JDBC 4.0, Java 6 adds the Java.sql.SQLXML type. This type can be used by a JDBC application to initialize, read, and store XML data. The Java.sql.Connection.createSQLXML method allows you to create a blank SQLXML object. Once this object is obtained, it is possible to initialize the represented XML data using methods such as SetString, Setbinarystream, Setcharacterstream, or Setresult.
enhancement of the sqlexcpetionPrior to Java SE 6, there were no more than 10 exception types for JDBC. This does not seem to be enough to describe an increasingly complex database exception condition. As a result, designers of Java SE 6 have made significant improvements to the java.sql.SQLException-rooted exception system.
The new exception classes in Ava 6 are divided into 3 types: sqlreoverableexception, Sqlnontransientexception, Sqltransientexception. There are several subcategories under Sqlnontransientexception and Sqltransientexception, which distinguish the various error situations that may occur in the JDBC program in detail. Most subclasses have a corresponding standard SQLState value, which is a good way to combine the SQL standard with the Java 6 class library.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"JDBC History" from JDBC1.0 to JDBC4.0

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.