JAVA study notes (thirteen)

JDBC

1 Overview

  JDBC (Java Data Base Connectivity, java database connection) is a Java API for executing SQL statements, which can provide unified access to a variety of relational databases. It consists of a set of classes and interfaces written in the Java language. It is the standard specification for Java to access the database

  JDBC provides a benchmark against which more advanced tools and interfaces can be built to enable database developers to write database applications.

  JDBC needs to be connected to a driver. The driver is that two devices need to communicate and meet a certain communication data format. The data format is specified by the device provider. The device provider provides driver software for the device, and the software can communicate with the device.

2. Principle

  JDBC is the interface, and the driver is the implementation of the interface. Without the driver, the database connection cannot be completed, so the database cannot be operated! Each database vendor needs to provide its own driver to connect to its own company's database, which means that the driver is generally provided by the database generation vendor.

3. JDBC development steps

  1. Register the driver.

    Tell the JVM which database driver to use

  2. Get connected.

    Use the classes in JDBC to complete the connection to the MySQL database

  3. Obtain the statement execution platform

    Get the executor object of the SQL statement through the connection object

  4. Execute the sql statement

    Use the executor object to execute SQL statements to the database

    Get the result of execution from the database

  5. Process the results

  6. Release resources.

    call a bunch of close() methods

  3.1 Import the driver jar package

  Create a lib directory to store all the jar packages required by the current project, select the jar package, right-click to execute build path / Add to Build Path

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324499853&siteId=291194637