Configuration method for accessing MySQL database using JDBC in eclipse

Source: Internet
Author: User
Tags wordpress database

 configuration method for accessing MySQL database using JDBC in EclipseCategory: DATABASE data structures and algorithms 2009-10-10 16:37 5313 People read review (+) collection report Jdbcmysql Database Eclipsewordpressproperties

This is an introductory article on JDBC, and the main content is how to use MySQL's JDBC driver in Eclipse.

To use JDBC to access MySQL databases, or other types of databases, you must have the JDBC driver for this database system. Typically, the JDBC driver is a jar file made by the database developer that encapsulates the code that communicates with the database system, and we just need to use it. To do this, please download the JDBC driver for your MySQL version, which is connector/j, on the MySQL website first. If you are too lazy to find it on the MySQL website, click here to download version 5.1 of connector/j.

The download should be a tar.gz or a zip package, we need the Mysql-connector-java-5.1.6.jar, this is the MySQL JDBC driver package. To extract this file to a place, the next thing to do is to add it to the Eclipse project so that the Java program can use it.

Create a new Java project in Eclipse, named "Jdbctest", and select "Properties" under the Project menu to go to the interface shown below.

Click the "Add External JARs ..." button to find the jar file that you just extracted, and when you're done, you'll see an extra "Mysql-connector-java ..." In the Configuration dialog box, and click the OK button below. The completion and JDBC drivers are added in the Eclipse project. The Package Explorer pane at the left should look like this:

The next step is to start writing Java code. On my machine, MySQL already has a database called WordPress, so I used directly. You'd better make a new database for testing.

For the code, let's just say it. Before you get the connection to MySQL, you must first register the MySQL driver class with System.setproperty ("Jdbc.drivers", "Com.mysql.jdbc.Driver"). Also specify the URL path to MySQL. The format of the URL is: jdbc:mysql://[domain name [: port (3306 port can be omitted)/[database name]. For example, the WordPress database URL on my machine is jdbc:mysql://localhost/wordpress. Next, use Drivermanager.getconnection (Url,user,password) to get a connection object. With the connection object, it is possible to create the statement object and execute the query statement. I won't say much about these technical details, as many books will write.

Reprinted from:

Http://hi.baidu.com/sosomagic1226/blog/item/e376f93f994aceea54e723a7.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.