First, JDBC Introduction:
JDBC (Java Data Connectivity,java database connection) is a JAVAAPI for executing SQL statements that provides unified access to a variety of relational databases, consisting of a set of classes and interfaces written in the Java language.
Second, the JDBC principle:
JDBC is the previous Sun company defined a set of access to the database interface (no specific implementation), a set of standards, the specific implementation is by the major database manufacturers to implement , each database manufacturers have their own JDBC implementation, that is, the JDBC driver implementation class, Java applications connect to the specified database and need to use the JDBC driver provided by the manufacturer to connect. (This is actually a Java polymorphic withdrawal, an interface can have a lot of specific implementation)
Third, JDBC Connection database steps
1. Load Driver
2. Connect to the database
3. Manipulating databases with statements
4. Close the database connection and release the resources;
Iv. Configuring Database Drivers in Eclipse projects (e.g.,Mysql-connector-java-5.1.40-bin.jar)
Right-click the project->build path->configure Build path->add exteranljars ....
V. Load data-driven
mysql driver name: Com.mysql.jdbc.Driver
Loading mode: Class.forName (driver name);
Vi. connection and closure of databases
1. DriverManager drive Management class, mainly responsible for obtaining a database connection;
2. Connection address format for MySQL database
JDBC:MYSQL://IP Address: Port number/database name
JDBC Protocol: The protocol in the JDBC URL is always jdbc;
Sub-Protocol: The name of the driver name or database connection mechanism, such as: MySQL
Sub-name: A way to identify a database. Must follow standard URL naming for "//hostname: Port/Database Name"
3. Connection interface to a specific database connection (session).
void Close () : Frees the database and JDBC resources for this connection object immediately, rather than waiting for them to be freed automatically
Upper and Lower code:
JDBC Overview and Connection database