MyEclipse------executeBatch()使用方法
2024-08-25 17:06:09
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>
最新文章
- 【thinkphp5】【THINKCMG】标签部分开发(一)
- gcc shared object
- js其它
- JQuery基础三
- Coin Change
- EasyDropDown – 很棒的下拉菜单 含精美主题
- POJ C程序设计进阶 编程题#1:分配病房
- 程序员必须知道的几个国外IT网站
- hdu 3535 AreYouBusy
- HDU 2050 折线分割平面 (递推)
- A Brief Introduction to the Design of UBIFS
- C++设计模式实现--组合(Composite)模式
- web打印小结
- 锐捷Linux版的下载和使用(福大客户端)
- Apache kylin概览
- AtCoder Regular Contest 082 (ARC082) E - ConvexScore 计算几何 计数
- Python Socket通信黏包问题分析及解决方法
- 优雅地记录Python程序日志1:logging模块简介
- 使用POI操作PPT文档(插入文本、图片)转
- C++中关于配置文件的问题
热门文章
- Hashtable 数据遍历的几种方式
- C语言中的深拷贝和浅拷贝
- CSS 动画之十-图片+图片信息展示
- GEOS库学习之四:几何关系判断
- [CareerCup] 11.7 Tower of People in Circus 马戏团的人塔
- 信息安全系统设计基础第一次实验报告 20135201&;&;20135306&;&;20135307
- 信息安全系统设计基础实验一:Linux开发环境的配置和使用
- 第四章 一切从IL开始
- 标准IDispose模式浅析
- Javascript基础系列之(七)函数(定义和调运函数)