package com.emon.dao.bo;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.emon.dao.BaseDao;
import com.emon.entity.Bo;
import com.util.DAOException;
import com.util.DBUtil;
public class BoDAO extends BaseDao{
public List<Bo> findByBo(String name, String deptName,
Integer level, int page, int pageSize) throws Exception{
// 参数值
List<Object> paramList = new ArrayList<Object>();
// 子查询SQL
StringBuffer sb = new StringBuffer();
sb.append("select a.*,rownum r from bo a where 1=1 ");
if (name != null && name.length() > 0) {
sb.append("and name=? ");
paramList.add(name);
}
if (deptName != null && deptName.length() > 0) {
sb.append("and deptName=? ");
paramList.add(deptName);
}
if (level!= null && level > 0) {
sb.append("and level1=? ");
paramList.add(level);
}
// 完整的SQL
String sql = "select * from (" + sb.toString() + ") where r<? and r>? ";
int nextMin = page * pageSize + 1;
// 当前页 结束 页
int lastMax = (page - 1) * pageSize;
paramList.add(nextMin);
paramList.add(lastMax);
System.out.println(sql);
Connection con = DBUtil.getConnection();
try {
PreparedStatement ps = con.prepareStatement(sql);
for (int i = 0; i < paramList.size(); i++) {
Object obj = paramList.get(i);
ps.setObject(i + 1, obj);
}
ResultSet rs = ps.executeQuery();
List<Bo> list = null;
while (rs.next()) {
Bo a = createBo(rs);
if (list == null)
list = new ArrayList<Bo>();
list.add(a);
}
return list;
} catch (SQLException e){
e.printStackTrace();
throw new DAOException("查询信息失败!", e);
}finally{
DBUtil.closeConnection();
}
}
private Bo createBo(ResultSet rs) throws SQLException {
Bo a = new Bo();
a.setId(rs.getInt("ID"));
a.setName(rs.getString("NAME"));
a.setDeptName(rs.getString("DEPTNAME"));
a.setLevel(rs.getInt("LEVEL1"));
return a;
}
public int findTotalPage(String name, String deptName,
Integer level, int pageSize) throws DAOException {
// 参数值
List<Object> paramList = new ArrayList<Object>();
// 查询SQL
StringBuffer sb = new StringBuffer();
sb.append("select count(*) from bo where 1=1 ");
if (name != null && name.length() > 0) {
sb.append("and name=? ");
paramList.add(name);
}
if (deptName != null && deptName.length() > 0) {
sb.append("and deptName=? ");
paramList.add(deptName);
}
if (level != null && level > 0) {
sb.append("and level1=? ");
paramList.add(level);
}
Connection con = DBUtil.getConnection();
try {
PreparedStatement ps = con.prepareStatement(sb.toString());
for (int i = 0; i < paramList.size(); i++) {
Object obj = paramList.get(i);
ps.setObject(i + 1, obj);
}
ResultSet rs = ps.executeQuery();
while (rs.next()) {
int rows = rs.getInt(1);
if (rows % pageSize == 0) {
return rows / pageSize;
} else {
return rows / pageSize + 1;
}
}
} catch (SQLException e) {
e.printStackTrace();
throw new DAOException("查询账务信息失败!", e);
} finally {
DBUtil.closeConnection();
}
return 0;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SSH增删改查一对多+分页
共232个文件
jar:51个
class:43个
java:42个
需积分: 10 25 下载量 190 浏览量
2015-07-23
11:19:16
上传
评论
收藏 21.7MB ZIP 举报
温馨提示
完全上传,包括jar,和数据库。SSh的增删改查,包括frameset,分页,数据库是oracle,
资源推荐
资源详情
资源评论
收起资源包目录
SSH增删改查一对多+分页 (232个子文件)
upload.bmp 700B
BoDAO.class 4KB
ListMemberPageAction.class 3KB
DBUtil.class 3KB
DeptImpl.class 3KB
UpdateEmpAction.class 3KB
EmpImpl.class 2KB
Emp.class 2KB
PageBean.class 2KB
DeleteEmpAction.class 2KB
LoginAction.class 2KB
AddDeptAction.class 2KB
MemberServiceImpl.class 2KB
UpdateEmpPageAction.class 2KB
TestCase.class 2KB
UpdateDeptAction.class 2KB
DeleteDeptAction.class 2KB
Dept.class 2KB
FindEmpAction.class 2KB
UpdateDeptPageAction.class 1KB
MemberDaoImpl$1.class 1KB
AddEmpPageAction.class 1KB
FindAllEmpAction.class 1KB
JumpAction.class 1KB
FindDeptAction.class 1KB
MemberDaoImpl.class 1KB
UserBase.class 1KB
OwnerAction.class 1KB
UserBaseimpl.class 1KB
Bo.class 1KB
TaskJob.class 912B
Page.class 744B
BoExportAction.class 663B
BaseDao.class 662B
IEmpDao.class 603B
AddDeptPageAction.class 591B
LeftFrameAction.class 583B
LoginPageAction.class 581B
IDeptDao.class 513B
DAOException.class 474B
BaseAction.class 297B
MemberDao.class 232B
IUserBaseDao.class 181B
MemberService.class 180B
.classpath 529B
org.eclipse.wst.common.component 448B
org.eclipse.wst.jsdt.ui.superType.container 49B
Thumbs.db 720KB
bg_over.gif 5KB
bg_selected.gif 2KB
error.gif 1KB
post.gif 563B
file.gif 554B
more.gif 502B
search.gif 478B
confirm.gif 380B
review.gif 380B
reject.gif 374B
revision.gif 364B
del.gif 351B
new.gif 261B
light.gif 255B
menu_r.gif 190B
026.gif 187B
subscribe.gif 159B
yes.gif 149B
bg.gif 132B
menu_back.gif 128B
cal.gif 127B
bg_tab_left.gif 106B
091.gif 95B
126.gif 68B
106.gif 64B
103.gif 64B
101.gif 64B
top.htm 270B
top1.html 355B
NewFile.html 126B
hibernate3.jar 2.17MB
ojdbc6.jar 2.01MB
spring.jar 1.75MB
xwork-core-2.1.6.jar 1.49MB
aspectjweaver.jar 1.47MB
freemarker-2.3.15.jar 859KB
spring-core-3.2.8.RELEASE.jar 853KB
spring-context-3.2.8.RELEASE.jar 846KB
freemarker.jar 784KB
struts2-core-2.1.8.jar 738KB
spring-webmvc-3.2.8.RELEASE.jar 623KB
spring-web-3.2.8.RELEASE.jar 614KB
spring-beans-3.2.8.RELEASE.jar 598KB
c3p0-0.9.1.jar 594KB
mchange-commons-java-0.2.6.3.jar 586KB
commons-collections-3.1.jar 546KB
commons-collections.jar 546KB
c3p0-0.9.5-pre6.jar 462KB
antlr-2.7.6.jar 433KB
quartz-all-1.6.0.jar 426KB
quartz-1.6.0.jar 412KB
hibernate-tools.jar 356KB
共 232 条
- 1
- 2
- 3
资源评论
qq_23009109
- 粉丝: 2
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功