Select the appropriate JDBC driver

xiaoxiao2021-03-06  115

If you don't understand the specific meaning of the JDBC drivers, or not understand which features are worthy of attention, it is not easy to choose the most appropriate one from a large number of drivers. This article will help you.

Overview

Speaking of the database driver, you can borrow a sentence of the comedian Rodney Dangerfield: "Do not take a leisurely". Many developers believe that the driver is just some of the tools that are determined, but in fact, the driver is often not as simple as the data converter or data pipeline, and some of their characteristics are extremely important, which affect the performance of the application and affects the application. The function is played. Java developers often need to access a wide variety of data sources including relational databases, and the JDBC driver uses JDBC standards to establish bridges between Java programs and data sources. Before the JDBC appeared, Java developers had to sink a variety of complex SQL statements in order to construct applications with database transactions. In order to solve this problem, Sun and its partners have developed JDBC APIs that simplify Java applications access to various data resources. As soon as you enter the world of JDBC drivers, you will have a dazzling feeling: the available drivers are too much! Although the right to choose is a good thing, for example, more than 160 JDBC drivers listed on the Sun website, but there is no detailed explanation which driver is better, where is it? Although according to the instructions, each driver supports certain important setup, but there is a problem to answer: In a specific environment, what is the meaning of these different drivers support? This is the problem to be discussed herein. Let's review some basic knowledge of JDBC standards and drivers. First, JDBC provides a way to complete the following basic tasks: ● Create and manage data source connections based on the URL or the DataSource object that is registered to the JNDI Name service. Therefore, the client does not have to perform a complex configuration. ● Construct the SQL command to send the SQL command to the data source. ● Extract and process returns to the Java application or the result set of applets. JDBC calls the Java database to the SQL statement that conversion into the table format data source. These data sources include both enterprise-class SQL database systems such as Oracle, SQL Server, IBM UDB, Informix, Sybase, etc., as well as data sources of spreadsheets and flat files, such as CSV, TSV, and mainframe data files. With JDBC, we can update multiple fields with a single command, handle multiple data sources (tables) in a single transaction. This means: ● Optimize data access performance by bulk processing. ● JDBC provides a public framework for accessing different database products, regardless of whether these database systems themselves have interoperable capabilities. ● Provide an abstraction layer for the data source. When the data source type changes, modify the data source definition is simpler. If the intermediate piece to be called by the client or the middle space server to be called does not belong to the developer control range, the JDBC provides the ability to access the data source via the Internet. JDBC has fully utilized Java portable, self-contained characteristics, avoiding multiple versions of the same application only due to platform and environment.

JDBC specification and driver classification

Now let's take a look at the JDBC specification. The JDBC specification has experienced several major version updates in history: ● JDBC 1.0: Provide basic features, emphasize ease of use. ● JDBC 2.0: Provides more advanced features and server-side processing capabilities. ● JDBC 3.0: Improve the API and optimize performance. Improved connection pools, statement buffering mechanisms, providing a migration path to the Sun connector system. Some options in the JDBC 2.0 specification, such as distributed transactions, are required in the JDBC 3.0 specification. At the same time, JDBC 3.0 also defines some new features, such as buffering pre-processed commands in the buffer pool. The initial Java language specification does not specify how Java programs access the database. But soon, Sun and its partners began to fill this gap. Early Java Data Access Policy Depends on the bridge that establishes an ODBC (ODBC is a data source access standard), the result is the JDBC-ODBC bridge driver. Today, the JDBC driver has four types: the first category: JDBC-ODBC bridge, plus ODBC drivers. Second Class: This machine API, part is a Java driver. Third category: Pure Java driver for database middleware. The fourth category: Pure Java driver directly facing the database. Third, four or two categories are pure Java drivers, so for Java developers, they have advantages in performance, portability, and function. The first class of the first class JDBC driver is a JDBC-ODBC bridge plus an ODBC driver. Sun suggests that the first type of driver is only used for prototyping, not to formally operate. The bridge driver is provided by Sun, its goal is to support traditional database systems. Sun provides patch for this software, but not supported by the software's end users. In general, bridging drivers are used in the case of investing in ODBC technology, such as a Windows application server already invested. Although Sun provides a JDBC-ODBC bridge driver, this technology does not apply to high-transactional environments due to ODBC loading binary code and database client code in the client. In addition, the first class JDBC driver does not support the full Java command set, but is limited to the function of the ODBC driver. The second type of second class JDBC driver is the driver of the partial Java code of the native API, which converts the JDBC call into the mainstream database API. This type of driver also has the same performance problem as the first type of driver, ie the client loaded into a binary code, and they are bound to a specific platform. The second type of driver requires the code to be a specific platform, which is probably not something that is really happy for any Java developer. Mainstream database vendors, such as Oracle and IBM, providing a second type of driver for their enterprise database platforms, using these drivers developers must keep up with different database vendors for each driver version issued by different operating systems. In addition, since the second type of driver does not use the pure Java API, when connecting the Java application to the data source, some additional configuration work must be performed. Many times, the second type of driver cannot be compatible with the data source of large hosts on the architecture; even if it is compatible, the effect is also a strong man. For this reason, most Java database developers choose a third type of driver, or choose a more flexible fourth-class pure Java new driver.

Figure 1: Comparison of the system of two types of drivers of the first, 2

Third Category 3 Class 3 JDBC drivers are pure Java drivers for database middleware, and JDBC calls are converted into an intermediate vendor's protocol, and the middleware converts these calls to the database API. The advantage of the third class JDBC driver is that it is based on the server, that is, the client code that needs the client, which makes the third type of driver than first and two. In addition, developers can also connect to a variety of databases using a single driver. The fourth class, four-class JDBC drivers are directly facing the pure Java driver for the database, the so-called "Thin" driver, which converts JDBC calls into some kind of network protocol used directly by DBMS, this, The client and application server can call DBMS servers directly. For a fourth class driver, different DBMS drivers are different. Therefore, in a heterogeneous computing environment, the number of drivers may be more. However, due to the high performance of the fourth type of driver, it is possible to directly access DBMS, so this problem is not so prominent. Figure 2: Comparison of the system of the third and fourth types of drivers

Select JDBC driver

Sun is in http://industry.java.sun.com/products/jdbc/drivers, and is shown in Figure 3. This page provides a driver selection tool that can display the required drivers according to the specified feature, allowing the specified feature to include driver types, supported JDBC versions, supported databases, and more. Today (September 2002), the driver collected by this page has reached 165! Many people use this selection tool to determine the drivers you have to use. So, there is a need to introduce this selection tool in detail: ● JDBC API Version: Select the JDBC version, optional from 1.x, 2.x or 3.x. ● Certified for J2EE: J2EE authentication, select J2EE 1.3 or J2EE 1.2 (one or all of which). ● Driver Type: Driver type, 1, 2, 3 or 4, any one or all. ● Supported DBMS: Supported DBMS, 83 options, most of which are database products of various vendors, but there are also industrial standards, such as JDBC, LDAP, ODBC, OLE DB Provider, Text (TSV), SQL / DS, and XML. You can choose one or more. ● Required Features: Required features, including DataSource, Conn. Pooling, Distributed Transaction (Dist. Trans.), A Recorder (Rowset,), or more. ● Returns Per Page: The number of results returned per page.

Figure 3: Sun's JDBC Driver Selection Tool

Let's take a look at what's the meaning of each option. The importance of JDBC API JDBC API is that it determines the functions available to Java developers. Early Java applications may not be able to use many of the advanced features provided by JDBC 3.0, but these features are essential for high transactions, distributed applications. Using the latest version of JDBC API, developers can use a variety of new DBMS and operating system security extensions, as well as the latest performance optimization mechanisms such as connecting pools, statement buffer pools, Rowsets objects. J2EE certification remember that JDBC is just a specification, not a standard implementation of a software. Each manufacturer can realize its own JDBC driver as needed. There are some drivers to follow J2EE specifications, and many drivers do not follow J2EE specifications. J2EE authentication of the JDBC driver (ie, get Certified for J2EE LOGO) is determined by Sun's CTS (Certification Test Suite). If a driver is to be judged than another excellent, it can be one of the standards that determine the quality of the driver . Generally we can think that through this certified vendor is more concerned about product quality, at http://java.sun.com/products/jdbc/industrial.html can find a manufacturer with related products and recognized (endorse) JDBC standards List. Required Character Schematic The three Required Features section provides a few JDBC drivers that are introduced in the JDBC 2.0 specification, but it is required in JDBC 3.0.

DataSource is an object that is managed by the JDBC driver. DataSource collaboration with JNDi services, instantiation and management of database connections are independent of their applications. Information related to the connection, such as paths, and port numbers, can be easily modified in the properties of the DataSource object, without having to change the application code using the data source. Currently, there are 62 supporting this feature in the total 165 drivers collected by Sun. JDBC supports connecting pools. The so-called connection pool is to allow some database connection objects to keep open in the buffer pool, so that any applications that request the database connection can get the database connection immediately, no longer need expensive network overhead Contact Database Server to get a connection, connect the poch. The idle connection to the local buffer pool gives the Java application that issues a request. When the application terminates the database connection, the database connection is actually not removed, but is returned to the connection pool buffer for other applications reuse, thereby effectively enhance database access performance. In the database transaction, establish a connection is the maximum operation of resource overhead. When an application tries to establish a database connection, multiple network interactions can be done (for example, for Oracle database connections, this number is 9). However, once the connection is successfully established, keep this connection again, reuse it in the later operation, and the overhead is much smaller. Database connection pool features greatly improve the potential for improved data transmission performance and scalability, especially for application servers. There are 62 support connecting pools in the JDBC driver in Sun collected. In a distributed system, applications often require multiple transaction to extract data, and data is often from multiple data sources. A business coordination system is required to coordinate a distributed transaction. For Java database developers, distributed transaction support may be the most important feature in addition to the performance indicators of the JDBC driver. Distributed Affairs requires additional resources to provide reliable support, mainly due to the delay of extracting data from different data sources, but also problems with interoperability. For example, it is not easy to distinguish between a failed transaction and a slower transaction, which requires the resource manager in the DTS to register and coordinate the Rollback or Commit operation in an appropriate manner while minimizing programming workload. Generally, distributed transactions use the Transaction Manager to coordinate different resource managers. There is an arbitration of the DTP (Distributed Transaction Processing) to provide an application and resource arbitration, which is possible to provide an ACID transaction across multiple data resources. In the case where you need multiple steps to get the desired results, there is a need to have a software module, which is usually a transaction manager, coordinating each process, such as IPlanet TrustBase Transaction Manager is such a product. 45 support this feature in the JDBC driver current SUN collected. Rowsets The object is the result set of queries, which contains records obtained from the table format data source. RowSet has an attribute and event alert mechanism similar to JavaBean, while it is also a Javabean component that can be created and used in a programming manner in a development environment. RowSets are connected to non-connected (disconnected, or called offline). Non-connected records need to be connected to the data source when extracting data, but no need for JDBC drivers when in non-connections. This record is small, commonly used to send data to the thin client. Non-connected record sets are contained in memory while saving also has its original data (Metadata) and connection, and execution instructions.

In contrast, the connected record set always keeps an open connection when used. The current SUN-collected drivers have 31 support record set properties, which are relatively small, perhaps because this feature is not often used. It must be pointed out that Sun's JDBC website defines "Support" RowSets to formally package and bring RowSets, so some drivers listed on this website may not support RowSets, but they actually Support multiple Rowsets. The JDBC 3.0 specification defines Prepared Statement Pooling (put the ready SQL statement into the buffer pool), which is not added to the JDBC driver search tool that is added to Figure 3, but it is sure that it will be searched soon. Features joins. From essentially, statement buffer is saved to the buffer pool that has been optimized and has run, once you need to perform it again, you may not have to make a pretreatment process such as optimization. The SQL statement pool can significantly improve performance. For any JDBC driver, it is a highlight worthy of attention. For SQL statements that need to be executed multiple times, the buffer prepared statements are particularly useful. For example, if a query function is to extract the current inventory value of a particular product category, run more frequently multiple times a day, then it can win from the statement buffer. When performing buffered SQL statements, simply incorporate parameters to query; all preprocessing steps, such as syntax checks, target legitimacy checks, optimized access paths, optimized execution plans, etc., have buffered in memory. For developers, the statement buffer pool has a special advantage, that is, it does not require developers to write any code (just like connecting pools). As long as you use a driver with a statement pool mechanism, you get the performance advantages of statement buffering. As long as JDBC driver support, statement pools and connecting pools can work simultaneously in an application. When the program uses a connection from the connection pool, all the connections that have previously run the SQL statement have the already defined statement pool. Therefore, even if the application is used to use a connection to prepare the SQL statement, it may not require the preparation process before the SQL statement execution. Conclude

The JDBC driver will produce a lot of significant impact on the application's performance. For the overall performance of the system, the characteristics of the JDBC driver are actually a critical factor. Not only in enterprise database applications, this problem is more prominent for applications to access distributed data resources. From a long-term vision, when you select a driver, please use the characteristics defined by JDBC 3.0, including DataSource objects, connect pools, distributed transaction support, RowSets, statement buffer pools, etc. as one of the selection criteria. As long as it is possible, you should choose the driver that directly operates the database API, instead of selecting drivers that are interactive with the database API after transition, as the former often has better performance performance. If performance and compliance with Java standards are essential, the driver is non-three and four categories. To find out the JDBC drivers that support the latest version specifications, provide the most enrichment, it is definitely a thing worth doing. There is also a factor that needs to be considered, and individual JDBC drivers provide some additional tools that are usually not available with the DBMS native driver, which may have an important impact on your development.

转载请注明原文地址:https://www.9cbs.com/read-125823.html

New Post(0)