Detailed steps for Java connection to MySQL database

This article mainly takes MySQL as an example to talk about how Java connects to the database. The specific contents are as follows

Of course, first install JDK (usually JDK1.5. X). Then install mysql. These are relatively simple. I won't talk about the specific process. After configuring the two environments, download the jdbc driver mysql-connector-java-5.0 5.zip (this is the latest version). Then unzip it to any directory. I unzip it to disk D, and then add mysql-connector-java-5.0.5-bin.jar in its directory to the classpath, as follows: "my computer" - > "properties" - > "advanced" - > "environment variables" @H_ 403_ 6@, edit the classpath in the system variable and put D: \ mysql-connector-java-5.0 5\mysql-connector-java-5.0. 5-bin. Add jar to the end, and add "; @ h_403_6 @" before adding this string to distinguish it from the previous classpath. Then confirm.

The environment is configured, which is very simple. Now, first configure MySQL and set its user name to "root" and password to "root". Create a database on the command line or with an SQL front-end software.

I use sqlyog's front-end software to create a database.

Create database first:

CREATE DATABASE SCUTCS;@ H_ 403_ 6@

Next, create a table:

Then insert the data. You can use the SQL statement insert into < table name > values (value1, Value2,...);

You can also use sqlyog to operate

All right, it's created.

Next, let's write it Java file to demonstrate how to access the MySQL database.

Next, let's run it to see the effect:

The execution results are as follows:

The above is the detailed steps of Java connecting to MySQL database. I hope it will be helpful for everyone's learning, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>