JDBC foundation (1)

xiaoxiao2021-03-06  20

JDBC Basics (1) I didn't want to write this entry-level content, but since the column is customized as a JDBC column, I still write some. JDBC foundation (1), we know! JDBC, Java platform Database connectivity In a vernacular, what does it mean? It is "Tools" on the Java platform and the database. Still first review the interface: from the bottom, the interface is the abstraction of "case", by a case abstract, some rules In turn, the interface from the top, abstract interface is a commitment and constraint for the case. That is, as long as you implement the interface I specified, your class has already had an interface to the external commitment method, as long as "Customer" will operate the interface, do not need to re-learn, will implement the new class of the interface! Ok, use it: 1. You can implement the same behavior of the unrelated class through the interface. 2. You can specify by the interface Multiple classes need to be implemented. 3. Understand the interaction method of the object without the need to understand the class of blue. These words are very clear? It seems to have a book for this model to use this paragraph More than 30 pages, the result is not as good as I understand, but I understand why some people want to write a book. I understand this thing, JDBC is so understandable. For general, Java There is a mechanism that has the same way to operate in the operation of different vendor databases, rather than every contact of a database, to learn new methods. "Things" to complete this mechanism is called "JDBC". Simple points JDBC has two parts, JDBC API and JDBC Driver Interface. JDBC API is provided to "customers" (that is, it is like this kind of rookie programmer, if it is a master written JDBC, haha) The group is independent of the API of the database, and the operation of any database can be done with this set of APIs. So the "instructions" that these universal APIs can be translated into specific databases, it is to be implemented by JDBC Driver Interface. So this is a programming interface for JDBC driver developers, which translates us to the generic instruction we send to the database to their own database through the JDBC API. Or use the actual operation to see how JDBC works. Because JDBC The API is a common interface, how is the program know which database I want to connect? So first loading (or registered available driver), in fact, JDBC signature. Load driver and a lot of ways, most Commonly used first to dissolve the driver class into memory as the "current" driver. Note "Current" is how many drivers can be in memory The program, but only the currently loaded drivers as the preferred link. Class.Forname ("org.gjt.mm.mysql.driver); class.forname method is to solve the signature in memory" org.gjt.mm .mysql.driver "DRIVER class, Driver class corresponding to the corresponding implementation class into the JDBC API interface. For example, the instance object of Org.gjt.mm.mysql.connection is assigned to the java.sql.connection interface handle, In order to "customer" can call the actual Org.gjt.mm.mysql.connection by operating the Java.sql.connection handle. It is, if they are mapped, this is the manufacturer programmed, "customers" as long as Class .forname ("org.gjt.mm.mysql.driver"); method can operate a JDBC API smoothly. The connection process of a normal database is: 1. Load the driver. 2. DraiverManager to a database link Handle. 3. Bind the statement to be executed by connecting the handle. 4. Receive the execution result. 5. Optional to the result of the result. 6. The necessary shutdown and database connection.

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

New Post(0)