MyEclipse------ExecuteBatch () How to use

Source: Internet
Author: User

The ExecuteBatch () method is used to execute the SQL statement in batches, but cannot execute the SQL statement that the return value is the resultset result set, but instead executes the stmt.executebatch () directly;

Auxiliary methods:

Addbatch (); Add an UPDATE statement to the batch.

Clearbatch (): Empty the UPDATE statement in the batch

testexecutebatch.jsp

<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%    StringPath=Request.getcontextpath (); StringBasePath=Request.getscheme ()+ "://"            +Request.getservername ()+ ":" +Request.getserverport ()+Path+ "/";%><%@page Import="java.sql.*" %><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML><Head><Basehref= "<%=basePath%>"><title>My JSP ' executebatch.jsp ' starting page</title></Head><Body>    <%        StringURL="jdbc:mysql://localhost:3306/student?usessl=true"; StringUsename="Root"; StringPassword="2277092"; Connection Conn=NULL; Statement stmt=NULL; try{Class.forName ("Com.mysql.jdbc.Driver"); //Out.print ("load Driver class succeeded");        } catch (Exception e) {out.print (e); } try{Conn=drivermanager.getconnection (Url,usename,password); stmt=conn.createstatement (); //use Addbatch () to add the SQL statement Stmt.addbatch ("INSERT INTO ClassInfo values (4, ' Shi Lan's ', ' Female ', ' Network engineering ', ' 2277092 ', ' Wuyi University ', ' ' + ');"); Stmt.addbatch ("Update ClassInfo set phone= ' 18814182472 ' where no=3113002421"); //use ExecuteBatch () to perform bulk UPDATE statement stmt.executebatch (); //statistics Update Count array/*            intaffectrowcounts[]=Stmt.executebatch ();  for(intI=0; I<Affectrowcounts.length;i++) {Out.print ("Section"+(i+1)+"the number of data rows affected by an UPDATE statement is:"+Affectrowcounts[i]+"<br>"); }            */Stmt.close (); Out.print ("Update Successful");        } catch (SQLException e) {out.print (e); } finally{try{if(conn!=NULL) Conn.close (); } catch (SQLException e) {out.print ("An exception occurred while shutting down the database connection"); }        }             %></Body></HTML>

MyEclipse------ExecuteBatch () How to use

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.