JDBC: Java DataBase Connectivity is an application programming interface (API) used in the Java language to regulate how clients access a DataBase. It provides methods such as querying and updating data in a DataBase.

Translate the definition:

As a Java programmer, the development of a project must involve the addition, deletion, change and check of the database.

But we know that there is more than one DBMS on the market, such as MySQL, Oracle, DB2, SQLite.

When we use MySQL, we need to write Java code to operate MySQL. When using Oracle, you need to write Java code to operate Oracle…

It’s too much trouble and expensive to learn.

So can we just use one Java code and operate on different databases?

Can!!!! And someone did it for us.

Oracle has written a set of apis for accessing and manipulating databases. Java programmers use this API to manipulate databases. This API is CALLED JDBC.

This SET of apis is the specification that each database vendor follows and implements the JDBC implementation classes. These implementation classes are also called driver classes.

Now let’s look at this sentence again:

JDBC is an application program interface (API) in the Java language that regulates how a client program accesses a database. JDBC provides methods such as querying and updating data in a database.

To sum up:

Database types are too many, programmers learn, use up too much trouble. As a result, a set of APIS, JDBC, is officially provided as the specification. Vendors and programmers adhere to it, database vendors implement apis, and programmers use this set of interfaces to program.

Take MySQL as an example. The MySQL vendor will implement the driver class as a JAR package mysql-connector-java-x.x.x for our use.

We use JDBC API programming, import mysql-connector-java-x.x.xjar package, in fact, the implementation of our JAR class method.

There is a People interface:

public interface People {
    
    void study(a);
}
Copy the code

The Student class implements the People interface and overwrites the study() method in the interface:

public class Student implements People {
    @Override
    public void study(a) {
        System.out.println("Study hard and make progress every day."); }}Copy the code

And then:

public static void main(String[] args) {
    People xiaoguan = new Student();
    xiaoguan.study();
}
Copy the code

Execute main method, console output: good good study, day day up

Please correct me if there are any mistakes


The article was first published on the public account “Pedestrian Insight”