JDBC Application Sample Experiment in Java

Source: Internet
Author: User

First, download the Mysql-connector-java-x.x.x-bin.jar package

    1. Download Mysql-connector-java-x.x.x-bin.jar, currently the latest version of Mysql-connector-java-5.1.22-bin.jar. (
    2. In Eclipse, select the project---Properties->java build path, and in the Libraries tab, select Add external jar to locate the downloaded Mysql-connector-java-5.1.22-bin.jar file and add it to the project.
    3. Compile again, the program runs normally! (Can be tested using the above code)

Ii. Examples of JDBC application experiments in Java

1  Packagecom.baorant;2 3 Importjava.sql.Connection;4 ImportJava.sql.DriverManager;5 Importjava.sql.PreparedStatement;6 Importjava.sql.SQLException;7 8  Public classJavademo {9     Ten      Public Static voidMain (string[] args)throwsException { OneString username = "root"; AString password = "li19941101"; -String url = "Jdbc:mysql://localhost:3306/mvc_user"; - Connection Conn; the         Try { -             //1. Load the database driver -Class.forName ("Com.mysql.jdbc.Driver");  -conn =drivermanager.getconnection (URL, username, password); +SYSTEM.OUT.PRINTLN ("Database connection succeeded! "); -  +             //The second step: Operation database; AString sql= "INSERT into User_info (User_id,user_name,password) VALUES (5, ' song ', ' SS ')"; atPreparedStatement pt=conn.preparestatement (SQL); - pt.executeupdate (); -             //Step three: Close the database; - conn.close (); -SYSTEM.OUT.PRINTLN ("Database operation succeeded! "); -}Catch(SQLException e) { in             //TODO auto-generated Catch block - e.printstacktrace (); to         } +     } -}

JDBC Application Sample Experiment in Java

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.