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