Take MySQL as an example to explain the steps of JDBC database connection
1. What is JDBC? What does it do?
Java Data Base Connectivity
Is a Java API for executing SQL statements, which can provide unified access to a variety of relational databases.
It provides a benchmark against which more advanced tools and interfaces can be built to enable developers to write database applications
With JDBC, it becomes easy to send SQL statements to various relational data
In other words, with JDBC API, there is no need to write a program to access Oracle database
Or write a program to access the MySQL database.
2. What are the operating steps for Java app to connect to the database and process data using JDBC?
Add the path where the driver package is located to the classpath classpath variable
(for example, copy mysql-connector-java-5.1.5-bin.jar to D: \ javasoft, and then add "D: / javasoft / mysql-connector-java-5.1.5-bin. Jar" to the value of classpath variable)
Steps:
1) Load driver
2) Create database connection object connection
3) Create a delivery object statement that can send SQL commands to the database and return results
4) Execute SQL commands and process the returned results
5) After processing, if a result set is returned, close the result set object resultset
6) Close the corresponding statement object
7) Close connection object connection
3. Case study 1