sql-Native JDBC Connection 7 steps

Source: Internet
Author: User

Native JDBC links are generally divided into 7 steps to get links and execute SQL statements

1, prepare 4 key parameters

    Static {        "jdbc:mysql://localhost:3306/test"  ;         " Com.mysql.jdbc.Driver " ;         " Root "  ;         " Root "  ;    }

2, registered Driver

new Com.mysql.jdbc.Driver ());

3, get links

Connect = drivermanager.getconnection (URL, userName, password);

4, Execute SQL statement

" SELECT * from Sys_user " ;             = connect.preparestatement (SQL);

5, get the result set

ResultSet = State.executequery ();

6, Result set processing

 while (Resultset.next ()) {                = resultset.getstring ("name");                 = Resultset.getstring (2);                System.  out "  " + Sex);            }

7, close the connection

 if(ResultSet! =NULL) {                Try{resultset.close (); } Catch(SQLException e) {e.printstacktrace (); }            }            if(state! =NULL) {                Try{state.close (); } Catch(SQLException e) {e.printstacktrace (); }            }            if(Connect! =NULL) {                Try{connect.close (); } Catch(SQLException e) {e.printstacktrace (); }            }

sql-Native JDBC Connection 7 steps

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.