The working mechanism of JDBC
Using JDBC to complete access to the database consists of the following five levels: Java application, jdbc API, JDBC driver, DBMS, and database.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/8E/wKioL1VMWW3gTD8cAACC1V07dtE004.jpg "title=" Untitled. png "alt=" wkiol1vmww3gtd8caacc1v07dte004.jpg "/>
The DBMS (Database management System) is the abbreviation for the databases Management system and is a large software that operates and manages databases for the establishment, use, and maintenance of databases. For example, MS SQL, Access, Oracle, Visual FoxPro, and so on are all part of the DBMS. DBMS can manage and control the database uniformly to ensure the security and integrity of the database. Users can access the data in the database through the DBMS, and the database administrator can maintain the database through the DBMS.
To access a database, Java applications should first load the JDBC driver for the specific database type with the JDBC API, and then access the various databases with the JDBC API. In short, JDBC can do three things: ① loads the JDBC driver and creates a database connection, ② sends the statement of the operational database to the DBMS and lets the DBMS execute it; ③ processes the returned results.
String MSODBC = "Sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName (MSODBC); Load Driver
String url = "Jdbc:odbc:javaodbc";
Connection conn = drivermanager.getconnection (URL); Establish a connection
Statement st = Conn.createstatement (); Create a statement object
St.executequery ("Select a,b,c from table"); Call the ExecuteQuery () method of the Statement object
JDBC URL parameter
The JDBC URL provides a way to identify the database so that the appropriate driver can identify and establish a connection to the database. The standard format for a JDBC URL consists of three parts, separated by colons, as follows:
jdbc:< Sub-Protocol >:< sub-name >
The meanings are as follows:
The protocol in the JDBC:JDBC URL is always JDBC.
< sub-Protocol;: Name of the driver name or database connection mechanism (this mechanism can be supported by one or more drivers). A typical example of a sub-protocol is ODBC, which indicates that JDBC is using the Jdbc-odbc bridge driver.
< database sub-name;: Typically, the name of the database, which must provide sufficient information for the location database.
Database operations
(1) Add record: INSERT into table name (field list) VALUES (Value list)
(2) Delete record: Delete form table name where condition
(3) Modify record: Update table name set field name = value WHERE condition
(4) Query record: Selete field 1, Field 2, Field 3,... from table name where condition