Java connection MySQL Database specific steps

Source: Internet
Author: User

Create a new folder in your project before you write the code, then copy the Java and MySQL drives into it and add it to build path, OK.

Import java.sql.Connection;

Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.Statement;




public class JBD {
private static final String URL = "JDBC:MYSQL://127.0.0.1:3306/IMOOC";
private static final String USER = "root";
private static final String PASSWORD = "OpenLab";
/**
* @param args
*/
public static void Main (string[] args) throws exception{
TODO auto-generated Method Stub
To load the database drive first
Class.forName ("Com.mysql.jdbc.Driver");

Get a database connection
Connection conn = drivermanager.getconnection (URL, USER, PASSWORD);

Operation database, to implement additions and deletions to search
Statement stmt = Conn.createstatement ();
ResultSet rs = stmt.executequery ("SELECT * from users");
while (Rs.next ())
{
System.out.println (rs.getstring ("sno") + rs.getshort ("sname"));


}
}


}


Open the database before you do that. The Run Code console then displays the SQL statement that is queried by the premises.

Java connection MySQL Database specific steps

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.