package com.school.dao.impl;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.school.dao.BaseDao;
import com.school.dao.StudentDao;
import com.school.entity.Student;
public class StudentDaoImpl extends BaseDao implements StudentDao {
@Override
public int queryCount() {
String sql="select count(*) from student";
Connection con=getConn();
PreparedStatement pstmt=null;
ResultSet rst=null;
int count=0;
try {
pstmt=con.prepareStatement(sql);
rst=pstmt.executeQuery();
if(rst.next()){
count=rst.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeConn(rst, pstmt, con);
}
return count;
}
@Override
public List<Student> queryForPage(int pageSize, int currPage) {
int count=(currPage-1)*pageSize;
String sql="select top "+ pageSize +"* from student where sid not in (select top "+count+" sid from student)";
return this.executeQuery(sql, null);
}
@Override
public boolean add(Student stu) {
String sql="insert into student values (?,?,?)";
String[]parmas={stu.getName(),String.valueOf(stu.getAge()),stu.getBirthday().toString()};
return this.executeUpdate(sql, parmas);
}
@Override
public boolean delete(int id) {
String sql="delete from student where sid=?";
String[]parmas={id+""};
return this.executeUpdate(sql, parmas);
}
@Override
public List<Student> executeQuery(String sql, String[] parmas) {
Connection con=getConn();
PreparedStatement pstmt=null;
ResultSet rst=null;
List<Student> list=new ArrayList<Student>();
try {
pstmt=con.prepareStatement(sql);
if(parmas!=null && parmas.length>0){
for(int i=0;i<parmas.length;i++){
pstmt.setString(i+1, parmas[i]);
}
}
rst=pstmt.executeQuery();
while(rst.next()){
int id=rst.getInt(1);
String name=rst.getString(2);
int age=rst.getInt(3);
Date birthday=rst.getDate(4);
Student stu=new Student(id,name,age,birthday);
list.add(stu);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
closeConn(rst,pstmt,con);
}
return list;
}
@Override
public List<Student> queryAll() {
String sql="select * from student";
return this.executeQuery(sql, null);
}
@Override
public List<Student> queryByName(String name) {
String sql="select * from student where sname like ?";
String[]parmas={"%"+name+"%"};
return this.executeQuery(sql, parmas);
}
@Override
public List<Student> queryByAge(int age) {
String sql="select * from student where sage="+age;
return this.executeQuery(sql, null);
}
@Override
public boolean update(Student stu) {
String sql="update student set sname=?,sage=?,birthday=? where sid=?";
String[]parmas={stu.getName(),stu.getAge()+"",stu.getBirthday().toString(),stu.getId()+""};
return this.executeUpdate(sql, parmas);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jsp 分页jsp 分页
共39个文件
class:11个
java:11个
jsp:8个
需积分: 16 77 下载量 94 浏览量
2011-06-11
22:15:08
上传
评论
收藏 419KB RAR 举报
温馨提示
jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页jsp 分页
资源推荐
资源详情
资源评论
收起资源包目录
指导学习分页.rar (39个子文件)
指导学习分页
sqlDemo5
.project 1KB
.settings
.jsdtscope 500B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 294B
WebRoot
login.jsp 839B
success.jsp 857B
do.jsp 585B
WEB-INF
web.xml 468B
lib
sqlserver2008.jar 413KB
classes
com
school
dao
LoginDao.class 511B
impl
StudentDaoImpl.class 5KB
LoginDaoImpl.class 3KB
BaseDao.class 2KB
StudentDao.class 929B
entity
Login.class 1KB
Student.class 1KB
execute
LoginExecute.class 1KB
StudentExecute.class 2KB
gui
StudentTest.class 2KB
util
Constants.class 366B
index.jsp 1KB
page.jsp 3KB
META-INF
MANIFEST.MF 36B
doAdd.jsp 496B
register.jsp 506B
time.jsp 532B
.myeclipse
src
com
school
dao
LoginDao.java 412B
impl
LoginDaoImpl.java 2KB
StudentDaoImpl.java 3KB
BaseDao.java 1KB
StudentDao.java 614B
entity
Login.java 746B
Student.java 966B
execute
StudentExecute.java 956B
LoginExecute.java 603B
gui
StudentTest.java 601B
util
Constants.java 234B
.classpath 438B
共 39 条
- 1
资源评论
shennianzhu
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功