The foundation of MYSQL--JDBC

Source: Internet
Author: User
Tags stmt

For my own JDBC always can't remember the question, I decided to write on the blog, every day to see-

Complete and workable examples:

1th:

Connect to JDBC

     Public StaticString Jdbc_url = "jdbc:mysql://xxxxxxx:3306/mlhx_log_1?useunicode=true&autoreconnect=true& Characterencoding=utf-8&allowmultiqueries=true ";  Public Static FinalString usr_name = "Xgame";  Public Static FinalString Usr_pass = "qingyouyile2013123456"; PrivateConnection con =NULL; PrivateStatement stmt =NULL;  Public voidinit () {Try{class.forname ("Com.mysql.jdbc.Driver"); Con=drivermanager.getconnection (Jdbc_url, Usr_name, Usr_pass); stmt=con.createstatement (); System.out.println ("Connect SUCC!"); } Catch(ClassNotFoundException |SQLException e) {System.out.println ("Connect Problem");        E.printstacktrace (); }    }

2nd:

Execute SQL statement

 Public ResultSet Execute (String sql) {        try  {            return  stmt.executequery (SQL) ;         Catch (SQLException e) {            System.out.println ("Query problem:" + sql);            E.printstacktrace ();        }         return NULL ;    }

3rd:

Turn off the connection

     Public void Close () {        try  {            stmt.close ();            Con.close ();            System.out.println ("Close succ!" );         Catch (SQLException e) {            System.out.println ("Close exception!" );            E.printstacktrace ();        }    }

The foundation of MYSQL--JDBC

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.