Java MySQL Pure Drive connection

Source: Internet
Author: User

 PackageSQL;Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.SQLException;Importjava.sql.Statement; Public classJdbctest { Public StaticString driver= "Com.mysql.jdbc.Driver";  Public StaticString url= "Jdbc:mysql://127.0.0.1:3306/test";  Public StaticString user= "Root";  Public StaticString password= "333";  Public Static voidMain (string[] args) {Connection con;        Statement Statement;        ResultSet rs; Try {            //Load DriverClass.forName (Driver); //connecting to a databasecon=drivermanager.getconnection (URL, user, password); if(!con.isclosed ()) System.out.println ("Connect successed"); Statement=con.createstatement (); String SQL= "SELECT * FROM TMP"; RS=statement.executequery (SQL);  while(Rs.next ()) {String RQ=rs.getstring ("RQ"); System.out.println ("Rq=" +RQ);            } rs.close ();                    Con.close (); } Catch(ClassNotFoundException e) {System.out.println ("Drive failed to load");        E.printstacktrace (); }Catch(SQLException e) {System.out.println ("SQL execution failed");        E.printstacktrace (); }Catch(Exception e) {}finally{                    }    }}

Java MySQL Pure drive connection

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.