Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the use of JDBC driver package

Shulou Source: shulou.com Published: 2022-06-01 09:37:39 09月26日 Update

This article mainly explains "what is the use of JDBC driver package", friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the use of the JDBC driver package"?

JDBC connection pool is mainly used to manage objects such as Connnection, Statement and ResultSet, but users only get their proxy objects (the management of these objects needs to be implemented by simulation drivers). These proxy objects also follow the JDBC interface specification, and these native objects are built through JDBC drivers, so let's take a look at how these objects are built inside the driver. Take MySQL driver (mysql-connector-java-5.1.48.jar) as an example

Step 1: extract the Jar package: first use the Winrar tool to extract the package

Step 2: find the directory where the driver class is located

Step 3: find the Connnection, Statement, ResultSet implementation classes under the package

Step 4: drag these three classes into Idea using the mouse, and they will be decompiled automatically

Step 5: see how Connection creates Statement and PreparedStatement

StatementImpl stmt = new StatementImpl (this.getMultiHostSafeProxy (), this.database)

* the driver itself supports PreparedStatement cache

Let's take a look at how it is turned off (Close)

Synchronization method off

Automatically closes the Statement,PreparedStatement,CallableStatement opened by it when the connection is closed

Step 6: take a look at the Statement internal implementation class

Put the openStatements property (CopyOnWriteArrayList) of ConnectionImpl when constructing

When Statement is turned off, it is automatically removed from the openStatements attribute (CopyOnWriteArrayList) of ConnectionImpl

Many business methods have this:

Synchronized (this.checkClosed () .getConnectionMutex ())

Such code actually only locks the Connection object.

* think again about the three-level shutdown check of the Little Bee connection Pool (BeeCP). Is it a bit similar?

How the driver package of Oracle is implemented (ojdbc7-12.1.0.2.jar) is actually similar internally.

Take a look at an example of stealing a beam for a post.

At this point, I believe you have a deeper understanding of "what is the use of the JDBC driver package?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Drivers objects methods similarity content properties agents learning management practicality deeper stealthood three business code examples interests but practical practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL Redmi Apple OPPO Reno