one or four kinds of driver concepts
A, Jdbc-odbc Bridge
Bridge-type drivers, which are characterized by the need to install the ODBC driver beforehand on the consumer's computer, and then access the database through ODBC using the Jdbc-odbc invocation method.
As part of the JDK1.1, it's part of the SUN.JDBC.ODBC package.
Application--->JDBC-ODBC bridge---->jdbc-odbc Library--->odbc driver-->database
For fast prototyping systems, no JDBC-driven database such as Access
B, jdbc-native API Bridge
Also one of the bridge drivers, which must first install a specific driver (like ODBC) on the consumer computer, and then convert the Java API call into a specific driver's invocation method, and then access the database through the conversion of the Jdbc-native API Bridge.
Use the local library provided by the developer to communicate directly with the database.
Application--->jdbc Driver---->native Database Library---->database
Slightly better than Class a performance.
C, Jdbc-middleware
The biggest benefit of this type of driver is that it eliminates the hassle of installing any driver on the consumer's computer, simply installing the middleware on the server side, and middleware is responsible for all the necessary transformations to access the database.
Application--->jdbc Driver----->java Middleware--->jdbc Driver---->database
Has the greatest flexibility, usually provided by those non-database vendors, and is the smallest of the four types.
D, Pure JDBC driver
This type of driver is the most sophisticated JDBC driver, which eliminates the need to install any additional drivers on the consumer computer, and does not require any mediations to be installed on the server side (middleware), and all operations that access the database are done directly by the driver.
Application--->JDBC driver----->database Engine--->database
The highest performance, communicates directly with the database engine through its own local protocol, and has the ability to assemble on the Internet.
ii. Common JDBC classes and methods
1, DriverManager class:
Responsible for managing JDBC drivers. Before using the JDBC driver, you must load the driver and register it with the DriverManager before you can use it, and provide a way to establish a connection to the database.
Method:
A, Class.forName (String driver); Load Registration Driver
B, Static Connection getconnection (String url,string user,string password) throws SQLException;
Getting a connection to a database
C, Static Driver getdriver (String url) throws sqlexcetion;
Look for a driver that can open the database specified by the URL in a driver that has been registered with the DriverManager
2, Connection Class
Responsible for maintaining the online between the Jsp/java database program and the database. You can create three very useful class objects.
Method:
A, Statement createstatement () throws SQLException; Creating Statement class Objects
Statement createstatement (int resultsettype,int resultsetconcurrency) throws SQLException;
Creating Statement class Objects
ResultsetType value
Type_forward_only result set cannot be scrolled
Type_scroll_insensitive result sets can be scrolled and do not reflect changes in the database
Type_scroll_sensitive result sets can be scrolled to reflect changes in the database
resultSetConcurrency value
Concur_read_only cannot update data with result sets
Concur_updatable can update data with result sets
Scrolling result sets are supported in JDBC2.0, and data can be updated
B, DatabaseMetaData GetMetaData () throws SQLException; Creating DatabaseMetaData class Objects
C, PreparedStatement preparestatement (String sql) throws SQLException;
Creating PreparedStatement class Objects
D, Boolean getautocommit () throws SQLException//return autocommit State of Connection class object
E, void Setautocommit (Boolean autocommit) throws SQLException
Setting the autocommit state of a connection class object
F, void Commit () throws SQLException//determine the operation of adding, deleting, or modifying records to the database
G, void rollback () throws SQLException//Cancel the operation of adding, deleting, or modifying records to the database
H, void Close () throws SQLException//End Connection object to the database online
I, Boolean isclosed () throws SQLException//test has closed connection class object to the database online
3, Statement class
The method provided by the statement class enables you to add, delete, or modify a database directly by using standard SQL commands
Method:
A, ResultSet executequery (String sql) throws SQLException//using the Select command to query the database
B, int executeupdate (String sql) throws SQLException
Use Insert/delete/update to add, delete, and modify the database.
C, void Close () throws SQLException//End Statement class object to the database online
4, PreparedStatement class
The difference between the PreparedStatement class and the statement class is that the PreparedStatement class object makes the incoming SQL command ready for use, and when a single SQL instruction is executed more than once, The PreparedStatement class is more efficient than the statement class.
Method:
A, ResultSet executequery () throws SQLException//using the Select command to query the database
B, int executeupdate () throws SQLException
Use Insert/delete/update to add, delete, and modify the database.
C, ResultSetMetaData GetMetaData () throws SQLException
Get information about fields in the ResultSet class object
D, void setint (int parameterindex,int x) throws SQLException
Sets the integer type value to the in parameter of the PreparedStatement class object
E, void setfloat (int parameterindex,float x) throws SQLException
Set the value of a floating-point number to the in parameter of the PreparedStatement class object
F, void setnull (int parameterindex,int sqltype) throws SQLException
Sets the null type value to the in parameter of the PreparedStatement class object
G, void setstring (int parameterindex,string x) throws SQLException
Sets the value of the string type to the in parameter of the PreparedStatement class object
H, void setdate (int parameterindex,date x) throws SQLException
Set Date type numeric value to the in parameter of the PreparedStatement class object
I, void settime (int parameterindex,time x) throws SQLException
Set the time type value to the in parameter of the PreparedStatement class object
5, DatabaseMetaData class
The DatabaseMetaData class holds all the attributes of the database, and provides many ways to obtain this information.
Method:
A, String Getdatabaseproductname () throws SQLException//Get database name
B, String getdatabaseproductversion () throws SQLException//Get Database Version code
C, String Getdrivername () throws SQLException//Get the name of the JDBC driver
D, String getdriverversion () throws SQLException//obtain version code of JDBC driver
E, String GetURL () throws SQLException//Get the JDBC URL of the connection database
F, String GetUserName () throws SQLException//Get the user account of the login database
6, ResultSet class
Responsible for storing the results of the query database. and provides a series of methods to add, delete and modify the database. Also responsible for maintaining a record pointer (Cursor), the record pointer to a record in the datasheet, through the appropriate mobile record pointer, can be arbitrary access to the database, enhance the efficiency of the program.
Method:
A, Boolean absolute (int row) throws SQLException//move record pointer to specified record
B, void Beforefirst () throws SQLException//move record pointer to first record
C, void Afterlast () throws SQLException//move record pointer after last record
D, Boolean First () throws SQLException//move record pointer to record
E, Boolean last () throws SQLException//move record pointer to final record
F, Boolean next () throws SQLException//move record pointer to next record
G, Boolean previous () throws SQLException//move record pointer to previous record
H, void DeleteRow () throws SQLException//delete records pointed to by record pointer
I, void Movetoinsertrow () throws SQLException//move record pointer to add a record
J, void Movetocurrentrow () throws SQLException//move record pointer to memory record
K, void InsertRow () throws SQLException//new record to database
L, void Updaterow () throws SQLException//modify a record in the database
M, void update type (int columnindex, type X) throws SQLException//Modify the value of the specified field
N, int get type (int columnindex) throws SQLException//Gets the value of the specified field
O, ResultSetMetaData GetMetaData () throws SQLException//Get ResultSetMetaData class object
7, ResultSetMetaData class
The ResultSetMetaData class object holds information about fields in all ResultSet class objects, providing a number of ways to obtain this information.
Method:
A, int getcolumncount () throws SQLException//Get the number of fields ResultSet class objects
B, int Getcolumndisplaysize () throws SQLException//Get ResultSet Class object's field length
C, String getcolumnname (int Column) throws SQLException//Get the field name of the ResultSet class object
D, String getcolumntypename (int column) throws SQLException//Gets the field type name of the ResultSet class object
E, String gettablename (int column) throws SQLException// Gets the name of the data table that the field of the ResultSet class object belongs to
F, boolean iscasesensitive (int column) throws SQLException// Tests whether the fields of the ResultSet class object are case-sensitive
G, boolean isreadonly (int column) throws SQLException// Tests whether the fields of the ResultSet class object are read-only