executeBatch()方法用于成批地执行SQL语句,但不能执行返回值是ResultSet结果集的SQL语句,而是直接执行stmt.executeBatch();

辅助方法:

addBatch();向批处理中加入一个更新语句。

clearBatch():清空批处理中的更新语句

testExecuteBatch.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%@page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'executeBatch.jsp' starting page</title>
</head> <body>
<%
String url="jdbc:mysql://localhost:3306/student?useSSL=true";
String useName="root";
String password="2277092";
Connection conn=null;
Statement stmt=null; try{
Class.forName("com.mysql.jdbc.Driver");
//out.print("加载驱动类成功");
}
catch(Exception e){
out.print(e);
} try{
conn=DriverManager.getConnection(url,useName,password);
stmt=conn.createStatement(); //使用addBatch()添加SQL语句
stmt.addBatch("insert into classinfo values(4,'石兰','女','网络工程','2277092','五邑大学','20','90');");
stmt.addBatch("update classinfo set phone='18814182472' where no=3113002421"); //使用executeBatch()执行批量更新语句
stmt.executeBatch(); //统计更新计数数组
/*
int affectRowCounts[]=stmt.executeBatch();
for(int i=0;i<affectRowCounts.length;i++){
out.print("第"+(i+1)+"个更新语句影响的数据行数为:"+affectRowCounts[i]+"<br>");
}
*/
stmt.close();
out.print("更新成功");
}
catch(SQLException e){
out.print(e);
}
finally{
try{
if(conn!=null)
conn.close();
}
catch(SQLException e){
out.print("关闭数据库连接出现异常");
}
} %>
</body>
</html>

最新文章

  1. 【thinkphp5】【THINKCMG】标签部分开发(一)
  2. gcc shared object
  3. js其它
  4. JQuery基础三
  5. Coin Change
  6. EasyDropDown – 很棒的下拉菜单 含精美主题
  7. POJ C程序设计进阶 编程题#1:分配病房
  8. 程序员必须知道的几个国外IT网站
  9. hdu 3535 AreYouBusy
  10. HDU 2050 折线分割平面 (递推)
  11. A Brief Introduction to the Design of UBIFS
  12. C++设计模式实现--组合(Composite)模式
  13. web打印小结
  14. 锐捷Linux版的下载和使用(福大客户端)
  15. Apache kylin概览
  16. AtCoder Regular Contest 082 (ARC082) E - ConvexScore 计算几何 计数
  17. Python Socket通信黏包问题分析及解决方法
  18. 优雅地记录Python程序日志1:logging模块简介
  19. 使用POI操作PPT文档(插入文本、图片)转
  20. C++中关于配置文件的问题

热门文章

  1. Hashtable 数据遍历的几种方式
  2. C语言中的深拷贝和浅拷贝
  3. CSS 动画之十-图片+图片信息展示
  4. GEOS库学习之四:几何关系判断
  5. [CareerCup] 11.7 Tower of People in Circus 马戏团的人塔
  6. 信息安全系统设计基础第一次实验报告 20135201&amp;&amp;20135306&amp;&amp;20135307
  7. 信息安全系统设计基础实验一:Linux开发环境的配置和使用
  8. 第四章 一切从IL开始
  9. 标准IDispose模式浅析
  10. Javascript基础系列之(七)函数(定义和调运函数)