JDBC connects MySQL, executes SQL statements in bulk, or executes an SQL statement before executing an SQL statement

Source: Internet
Author: User

conn =mysqljdbcutils.getconnection (); Statement PS=conn.createstatement ();p S.addbatch ("Truncate Qb_showcount_asite_copy");p S.executebatch (); String Srcsql= "SELECT Convert" (Unhex (Hex (CONVERT (Community using latin1)) using UTF8) as Community, PID from Qb_menbercmmsets_list whe Re site=7 "; stmt=conn.preparestatement (Srcsql); RS=Stmt.executequery () above is the empty command executed before the following SQL statement is executed//Bulk execution of SQL statementsSolution One statement PS=conn.createstatement ();p S.addbatch ("Update user set money=money-100 where name= ' Zhang San '");p S.addbatch ("Update user set money=money+100 where name= ' John Doe '");p S.addbatch ("Update temp set count=count+1 where Name= ' Zhang San '");p S.executebatch (); However, the use of statement, can only be used to use the concatenation of strings, to pass the value; scenario two if multiple statements are repeated, but the parameters are unchanged, you can preparedstatement PS=conn.preparestatement ("INSERT into temp values (?)");p S.setint (1, 100);p S.addbatch ();p S.setint (1, 200);p S.addbatch ();p s.executebatch (); Scenario three write a stored procedure Laugh reference http://blog.csdn.net/cnmcxiari/article/details/6632975

JDBC connects MySQL, executes SQL statements in bulk, or executes an SQL statement before executing an SQL statement

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.