Java JDBC connects to MySQL database to realize the operation of addition, deletion, modification and query

JDBC is no stranger to us. As long as you are engaged in Java, you have to learn such a thing when you first contact J2EE. Who calls the program to deal with the database! JDBC is a very basic knowledge to deal with databases, and it is also close to the bottom. In fact, more mature frameworks are used in practical work, such as hibernate and mybatis.

However, as the underlying JDBC of these mature frameworks, we should also master it. Only by understanding the addition, deletion, modification and query of JDBC, can we better understand how these mature frameworks implement the addition, deletion, modification and query if we are interested in studying the source code of hibernate or mybatis in the future.

Back to the point, let's take a look at our development environment:

Java language, eclipse development tool, MySQL database, Navicat database visualization tool.

Please refer to the data (very simple) for the installation, construction and use of the development environment, which will not be described in detail here.

The first step is to create a database. Use the Navicat database visualization tool to create a database casually. Create a table in the library, and give several fields in the table (remember to give an ID field, unique primary key, self increment sequence), and then give two pieces of data casually to test the function, as shown in the figure:

The second step is to get through the database (in this example, I hope you can knock it out by yourself. It won't take much time. Get familiar with how JDBC deals with the database, so it is shown in the figure), as shown in the figure:

The third step is to transform the dbutil class to facilitate the connection to the database at the Dao layer. The code is as follows:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>