What is 1.JDBC?
JDBC (Java database Connectivity) Java DB connection
What can 2.JDBC do?
In short, JDBC can do three things: establish a connection to the database, send a statement that operates the database, and process the results.
What is the advantage of 3.JDBC?
Java is a strong, secure, easy-to-use, easy-to-understand and automatically downloadable feature on the Web, and is an excellent language for writing database applications. All that is needed is a way for a conversation between a Java application and a variety of different databases.
4.JDBC implementation?
JDBC defines interfaces
Database Vendor Implementation Interface
The programmer invokes the interface, and the actual invocation is the implementation part of the underlying data vendor.
Implementations generally have several steps:
(1) Driver interface and driver class loading
Different types of databases will have different driver classes.
For example, we can load the Oracle driver class via Class.forName ("Oracle.jdbc.driver.OracleDriver");
(2) Connection interface
The real implementation of the connection interface is done by the driver package provided by the database vendor.
String=url;
Connection conn=drivermanager.getconnection ("URL", "DatabaseName", "password")
Different types of databases will have different URLs.
(3) Statement interface
Statement: Created by Method Createstatement. The statement object is used to send a simple SQL statement.
PreparedStatement: Created by Method Preparestatement. The PreparedStatement object is used to send an SQL statement with one or more input parameters (in parameters). PreparedStatement has a set of methods for setting the value of the in parameter. These in parameters are sent to the database when the statement is executed. The PreparedStatement instances extend the statement, so they all include the statement method. The PreparedStatement object may be more efficient than the statement object because it has been precompiled and stored there for future use.
The Statement interface provides three ways to execute SQL statements: ExecuteQuery, Executeupdate, and execute.
(4) ResultSet interface
Used to process the results of SQL statement execution.
(5) Closing the object
The statement object will be automatically shut down by the Java garbage collection program. As a good programming style, you should explicitly close them when you don't need statement objects. This frees the DBMS resources immediately, helping to avoid potential memory problems.
Uncover the mysteries of JDBC so that JDBC is no longer mysterious