The full name of JDBC is the Java database Connectivity, a set of object-oriented application interfaces (APIs) that provide a unified standard interface for accessing various relational databases, providing the implementation of standard interfaces for each database vendor. This thing can realize the platform of Software.
JDBC is an underlying API that accesses a database by embedding SQL statements directly into the business logic.
JDBC does not have direct access to the database and must rely on the JDBC driver provided by the database vendor to complete the following three steps 1. Establish a connection with the database; 2. Send SQL statements to the database; 3. Process the results returned from the database.
*JDBC Drive
1.jdbc-odbc Bridge is connected to the RDBMS via the local OBDC driver.
The 2.jdbc-native Bridge implements a database connection by invoking a local native program, which turns the JDBC call on the client API into a call to ORACLE,SYBASE,INFORMIX,DB2 or other DBMS.
The 3.JDBC network driver is a JDBC driver that is written entirely in the Java language.
4. The local protocol driver is a JDBC driver that is written entirely in the Java language, and this type of driver translates the JDBC call directly into the network protocol used by the DBMS.
#JDBC中常用接口
-driver interface
The driver for each database should provide a class that implements the Java.sql.Driver interface, referred to as the driver class.
Load JDBC-ODBC driver:
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
-drivermanager class
The Java.sql.DriverManager class is the basic service for managing the JDBC driver, a JDBC management layer that acts between the user and the driver, is responsible for tracking the available drivers, and establishes a connection between the data and the driver.
(static method) getconnection (String url,string user,string password) is used to establish a database connection.
setLoginTimeout (int seconds) is used to set the maximum time per database connection
println (String message) used to output the specified message to the current JDBC journaling stream
-connection interface
The Java.sql.Connection interface represents a connection to a particular database, can execute SQL statements and return results in a successive context, and can also obtain relevant information provided by the database through the GetMetaData () method.
Createstatement () Creates and returns an instance of statement, typically when the SQL statement that executes the parameterless is created.
-statement interface
The Java.sql.Statement interface is used to execute static SQL statements and return execution results.
For Insert,ipdate and DELETE statements, call the executeupdate (String sql) method, and for the SELECT statement, call the ExecuteQuery (String sql) method, and returns a ResultSet instance that can never be null.
-preparedstatement interface
The Java.sql.PreparedStatement interface inherits and extends the statement interface for executing dynamic SQL statements, which are SQL statements that contain parameters.
When assigning a value to a parameter in an SQL statement through the SETXXX () method, it is recommended that you use a method that matches the parameter type, or you can assign a value to various types by using SetObject ().
Preparedstetement ps=connection.preparedstatement ("SELECT * from table_name where ID>? and (name=? or name=) ");
Ps.setint (1,6);
Ps.setstring (2, "Mr. Ma");
Ps.setobject (3, "Mr. Li");
ResultSet Rs=ps.executequery ();
Clearparameters () Clears the value of the current parameter.
-callablestatement interface
The Java.sql.CallableStatement interface inherits and extends the PreparedStatement interface, which is used to execute SQL stored procedures.
-resultset interface
The Java.sql.ResultSet interface is similar to a data table, through which an instance of the interface can obtain a result set and related information about the corresponding data table, and the ResultSet instance is generated by executing the query database statement.
The next () method moves the pointer to the next line, returning the bool type. You can only iterate once!
The GetXxx () method has two overloaded methods that retrieve column values based on the index number of the column and the name of the column.
First (), returns the BOOL value
Last (), returns the BOOL value
Previous () Moves the pointer to the previous line, returning a bool value
Beforefirst ()
Afterlast ()
Absolute () moves to the specified line, int>0 moves down, int<0, moves backwards
Relative () moves to the specified line relative to the current position, int>0 moves down, int<0, moves backwards
GetRow () current row index number
Findcolumn () View the index number of the specified column name
Isbeforefirst () to see if the pointer is at the beginning of the instance, return bool
IsFirst () to see if the pointer is in the first row, return bool
DeleteRow () Deletes the current row, and after executing the method, it is not synchronized to the database until close () is executed
Http://www.cnblogs.com/rond/articles/1907133.html
JDBC Database Programming Common interface (GO)