MySQL loads the JDBC driver and mysql loads the jdbc driver.

Source: Internet
Author: User

MySQL loads the JDBC driver and mysql loads the jdbc driver.

First, install the MySQL database. MySQL5.5 is installed. The installation steps are not described here. Please note that if the installation process stops at the start service and cannot continue, please refer to my blog post "when installing MySQL5.5, the start service does not respond, solution", it should help you solve the problem.

Next, go to MySQL Official Website. This is an image file. Double-click it to automatically install the file and generate a MySQL Connector J folder in the C: \ Program Files \ MySQL folder. Go to the folder and find a file named mysql-connector-java-5.1.35-bin.jar.

My java program is installed in the D: \ Java \ jdk1.7.0 _ 15 folder, find the lib folder under the folder, and copy the mysql-connector-java-5.1.35-bin.jar to lib. When the java Program is installed, a lib folder is generated in C: \ Program Files \ Java \ jre by default. in this folder, locate ext and double-click to enter the folder, at the same time, copy a copy of The mysql-connector-java-5.1.35-bin.jar into it.


Remember to configure CLASSPATH:

My CLASSPATH configuration :.; % JAVA_HOME % \ lib; % JAVA_HOME % \ lib \ dt. jar; % JAVA_HOME % \ lib \ tools. jar; % JAVA_HOME % \ lib \ mysql-connector-java-5.1.36-bin.jar;

Use normally in dos environment;

In Eclipse, right-click the project, right-click Build Path, and select Configure Build Path. An Attribute diagram is displayed. Select Libraries under Java Build Path, click Add External JARs, browse to the JDBC MySQL driver jar package, and click OK to import it to the project.

After completing the preceding steps, you can use java to operate the MySQL database.


  1. // There are only four steps: 1. Load the driver; 2. Connect to the database; 3. Execute the command; 4. Disable the database;
  2. Import java. SQL .*;
  3. Class MysqlConnection
  4. {
  5. /* If you change the database, replace these statements directly. The main function does not need to be moved, mainly because of the driver and the connection method (DBURL )*/
  6. Private static String DBDRIVER = "org. gjt. mm. mysql. Driver"; // This corresponds to the driver. class file downloaded from jdbc-mysql. You
  7. // You can decompress the package and find out that the driver is the ghost ..
  8. Private static String DBURL = "jdbc: mysql: // localhost: 3306/study ";/*
  9. The jdbc: mysql: // localhost: 3306: test statement is parsed as follows:
  10. Jdbc: mysql: // indicates the JDBC connection method;
  11. Localhost: Your local address;
  12. 3306 sqldatabase port number;
  13. Study is the address of the database you want to connect.
  14. You can try not to use this 'Study ', or randomly connect to a nonexistent database,
  15. Then you can run the following statement to connect to the database ()
  16. */
  17. Private static String DBUSER = "scott ";
  18. Private static String DBPASSWORD = "tiger ";
  19. Public static void main (String [] args) throws Exception
  20. {
  21. Class. forName (DBDRIVER); // 1. Load the driver
  22. Connection conn = DriverManager. getConnection (DBURL, DBUSER, DBPASSWORD); // 2. Obtain the link
  23. Statement statement = conn. createStatement (); // 3. Execute the command
  24. // Statement.exe cuteUpdate ("use study"); // (a) if the above database does not exist, use this function to connect to the database.
  25. ResultSet result = statement.exe cuteQuery ("SELECT * FROM emp"); // result collection, Iteration
  26. While (result. next ()){
  27. Printf (result. getObject (1) + "");
  28. Printf (result. getObject (2) + "");
  29. Printf (result. getObject (3) + "");
  30. Printf (result. getObject (4) + "\ n ");
  31. }
  32. Conn. close ();
  33. }
  34. Public static void printf (Object obj ){
  35. System. out. print (obj );
  36. }
  37. Public static void printfln (Object obj ){
  38. System. out. println (obj );
  39. }
  40. }




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.