package y2javaee.sg.util;
import java.util.*;
import java.sql.*;
import javax.servlet.jsp.jstl.sql.*;
/*
* 通用的JDBC数据库访问类
* Y2JavaEE的ch06的工具类
*/
public class SQLCommandBean {
private Connection conn;
private String sqlValue;
private List values;
/**
* 设定连接类
*/
public void setConnection(Connection conn) {
this.conn = conn;
}
/**
* 设定SQL语句.
*/
public void setSqlValue(String sqlValue) {
this.sqlValue = sqlValue;
}
/**
* 设定SQL语句的参数
*/
public void setValues(List values) {
this.values = values;
}
/**
* 执行查询
*
* @return a javax.servlet.jsp.jstl.sql.Result object
* @exception SQLException
*/
public Result executeQuery() throws SQLException {
Result result = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
Statement stmt = null;
try {
if (values != null && values.size() > 0) {
// Use a PreparedStatement and set all values
pstmt = conn.prepareStatement(sqlValue);
setValues(pstmt, values);
rs = pstmt.executeQuery();
}
else {
// Use a regular Statement
stmt = conn.createStatement();
rs = stmt.executeQuery(sqlValue);
}
result = ResultSupport.toResult(rs);
}finally {
if (rs != null) {
try {rs.close();} catch (SQLException e) {}
}
if (stmt != null) {
try {stmt.close();} catch (SQLException e) {}
}
if (pstmt != null) {
try {pstmt.close();} catch (SQLException e) {}
}
}
return result;
}
/**
* 执行Update语句
*
* @return the number of rows affected
* @exception SQLException
*/
public int executeUpdate() throws SQLException {
int noOfRows = 0;
ResultSet rs = null;
PreparedStatement pstmt = null;
Statement stmt = null;
try {
if (values != null && values.size() > 0) {
// Use a PreparedStatement and set all values
pstmt = conn.prepareStatement(sqlValue);
setValues(pstmt, values);
noOfRows = pstmt.executeUpdate();
}
else {
// Use a regular Statement
stmt = conn.createStatement();
noOfRows = stmt.executeUpdate(sqlValue);
}
}
finally {
if (rs != null) {
try {rs.close();} catch (SQLException e) {}
}
if (stmt != null) {
try {stmt.close();} catch (SQLException e) {}
}
if (pstmt != null) {
try {pstmt.close();} catch (SQLException e) {}
}
}
return noOfRows;
}
/**
* 设定语句的参数.
*
* @param pstmt the PreparedStatement
* @param values a List with objects
* @exception SQLException
*/
private void setValues(PreparedStatement pstmt, List values)
throws SQLException {
for (int i = 0; i < values.size(); i++) {
Object v = values.get(i);
// Set the value using the method corresponding to the type.
// Note! Set methods are indexed from 1, so we add 1 to i
pstmt.setObject(i + 1, v);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
accp5.0\教学电子课件\Y2\开发基于JSP Servlet JavaBean的网上交易系统(JSP Servlet JavaBean Web Service)\ACCP5.0 开发基于JSP Servlet JavaBean的网上交易系统理论课贯穿案例.rar
资源推荐
资源详情
资源评论
收起资源包目录
JSP Servlet JavaBean的网上交易系统理论课贯穿案例 (250个子文件)
ProcessOrder.class 4KB
TitlesBean3.class 3KB
CreditcardServiceTest.class 3KB
SQLCommandBean.class 3KB
TitlesBean.class 3KB
TitlesBean2.class 3KB
TitlesBean.class 3KB
AddBookToCart.class 2KB
AddBookToCart.class 2KB
AddBookToCart.class 2KB
TestSQLCommBean.class 2KB
AddBookToCart.class 2KB
ConnectionManager.class 2KB
ConnectionManager.class 2KB
TitlesBean.class 2KB
AddBookToCart.class 2KB
Register.class 2KB
UserManager.class 2KB
Counter.class 2KB
HelloServlet.class 2KB
ProcessOrder.class 2KB
Authenticate.class 2KB
CheckLogin.class 2KB
ConnectionManager.class 2KB
ConnectionManager.class 2KB
BookBean.class 2KB
OrderOperation.class 2KB
OrderOperation.class 2KB
BookBean.class 2KB
BookBean.class 2KB
Order.class 2KB
ProcessCreditCard.class 2KB
Simplebean.class 1KB
Env.class 1KB
Env.class 1KB
CartItemBean.class 924B
CartItemBean.class 853B
User.class 799B
Person.class 781B
DBAccessException.class 733B
DBAccessException.class 717B
PersonTest.class 646B
IProcessCredit.class 175B
.classpath 3KB
main.css 2KB
styles.css 2KB
styles.css 2KB
styles.css 2KB
styles.css 2KB
styles.css 2KB
Thumbs.db 191KB
bn01~.gif 49KB
bk.gif 6KB
msn.gif 4KB
qq.gif 169B
top01.gif 126B
icon1.gif 104B
bnbg1.gif 92B
topbt5.gif 82B
topbt3.gif 80B
topbt1.gif 80B
topbt4.gif 80B
topbt2.gif 80B
leftbg.gif 44B
order.html 5KB
order.html 5KB
register2.html 4KB
register.html 4KB
order.html 4KB
order.html 4KB
register2.html 4KB
register.html 4KB
order.html 4KB
index.html 2KB
register.html 927B
register.html 927B
index.html 378B
xbean-2.1.0.jar 2.52MB
xfire-all-1.2.6.jar 883KB
xalan.jar 876KB
wstx-asl-2.9.3.jar 427KB
mssqlserver2.jar 402KB
standard.jar 384KB
xfire-core-1.1.2.jar 381KB
mail-1.4.jar 380KB
saaj-impl-1.3.jar 268KB
jaxen-full.jar 187KB
commons-beanutils-1.7.0.jar 184KB
jdom-1.0.jar 150KB
xbean-spring-2.4.jar 131KB
wsdl4j-1.5.2.jar 124KB
xfire-aegis-1.1.1.jar 114KB
XmlSchema-1.0.3.jar 109KB
activation-1.1.jar 62KB
commons-codec-1.3.jar 46KB
xfire-jaxws-1.1.2.jar 44KB
xfire-generator-1.1.2.jar 40KB
commons-logging-1.0.4.jar 37KB
stax-api-1.0.1.jar 26KB
xfire-annotations-1.1.2.jar 24KB
共 250 条
- 1
- 2
- 3
资源评论
- ivan6454066892012-11-22项目贯穿案例不错,清晰地显示代码的详解。可以作为学习的辅助文件,熟练掌握Servlet的使用
xuyuan87
- 粉丝: 4
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python编程与OpenCV、OpenPose人体姿态估计实战指南
- Matlab仿真CNN卷积神经网络:手写数字识别深度学习实战
- 在嵌入式开发中,经常会利用命令行交互系统测试功能,本文描述使用C++语言开发的一个命令行交互系统,支持命令注册(C或C++格式)
- 基于YOLOv5和LPRNet进行车牌检测+识别CCPD数据集源码+模型+超详细教程.zip
- neo4j社区版下载,免费下载
- python代码实现视频转动漫效果
- 昆仑通泰触摸屏和扫码枪通讯
- 电子通信设计资料短波无线监听发射器1(100MHz)
- QT项目dump机制使用,cv2pdb.exe - v0.52
- 基于yolov5车牌检测源码+模型+项目说明.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功