package com.ls.dao.impl;
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 java.util.Map;
import com.ls.entity.Students;
import com.ls.util.Dbutil;
import com.ls.util.PageModel;
public class Istudent implements Impstudent{
@Override
public List<Students> queryStu(String name, int age) {
// TODO Auto-generated method stub
List<Students> list =new ArrayList<Students>();
Dbutil db=new Dbutil();
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select * from students";
try {
conn=db.getConnection();
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
Students stu=new Students( rs.getInt("stu_no"),
rs.getString("stu_name"),
rs.getString("stu_sex"),
rs.getInt("stu_age"),
rs.getString("stu_birth"));
list.add(stu);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
db.closeDb(rs, ps, conn);
}
return list;
}
@Override
public boolean saveorupdate(Students stuEnt) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement ps=null;
conn=new Dbutil().getConnection();
boolean bool=false;
try {
if(stuEnt.getStu_no()>0&& !("").equals(stuEnt.getStu_no())){
String sqluadate="Update students set stu_name=?,stu_sex=?,stu_age=?,stu_birth=? where stu_no=?";
ps=conn.prepareStatement(sqluadate);
ps.setString(1, stuEnt.getStu_name());
ps.setString(2, stuEnt.getStu_sex());
ps.setInt(3, stuEnt.getStu_age());
ps.setString(4, stuEnt.getStu_birth());
ps.setInt(5, stuEnt.getStu_no());
int rowNum=ps.executeUpdate();
if(rowNum>0){
bool=true;
}
}else{
String addsql="insert into students(stu_no,stu_name,stu_sex,stu_age,stu_birth) values(?,?,?,?,?)";
ps=conn.prepareStatement(addsql);
ps.setInt(1, stuEnt.getStu_no());
ps.setString(2, stuEnt.getStu_name());
ps.setString(3, stuEnt.getStu_sex());
ps.setInt(4, stuEnt.getStu_age());
ps.setString(5, stuEnt.getStu_birth());
int rowNum=ps.executeUpdate();
if(rowNum>0){
bool=true;
}
}
} catch (Exception e) {
// TODO: handle exception
}finally{
new Dbutil().closeDb(null, ps, conn);
}
return bool;
}
@Override
public Students getStudentsInfo(int id) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
Students stu=null;
conn=new Dbutil().getConnection();
String sql="select * from students where stu_no=?";
try {
ps=conn.prepareStatement(sql);
ps.setInt(1, id);
rs=ps.executeQuery();
if(rs.next()){
stu=new Students( rs.getInt("stu_no"),
rs.getString("stu_name"),
rs.getString("stu_sex"),
rs.getInt("stu_age"),
rs.getString("stu_birth"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
new Dbutil().closeDb(rs, ps, conn);
}
return stu;
}
@Override
public boolean deleteStu(int id) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement ps=null;
boolean bool=false;
conn=new Dbutil().getConnection();
String sql="delete from students where stu_no=?";
try {
ps=conn.prepareStatement(sql);
ps.setInt(1, id);
int i=ps.executeUpdate();
if(i>0){
bool=true;
}else{
bool=false;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
new Dbutil().closeDb(null, ps, conn);
}
return bool;
}
@Override
public List<Students> selectInfo(int id, String name) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
List<Students> list=new ArrayList<Students>();
conn=new Dbutil().getConnection();
String sql="select * from students where stu_no=? or stu_name=?";
try {
ps=conn.prepareStatement(sql);
ps.setInt(1, id);
ps.setString(2, name);
rs=ps.executeQuery();
while(rs.next()){
Students stuEnt=new Students( rs.getInt("stu_no"),
rs.getString("stu_name"),
rs.getString("stu_sex"),
rs.getInt("stu_age"),
rs.getString("stu_birth"));
list.add(stuEnt);
};
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
new Dbutil().closeDb(null, ps, conn);
}
return list;
}
public List<Students> selectInfo(String name) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
List<Students> list=new ArrayList<Students>();
conn=new Dbutil().getConnection();
String sql="select * from students where stu_no=? or stu_name=?";
try {
ps=conn.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, name);
rs=ps.executeQuery();
while(rs.next()){
Students stuEnt=new Students( rs.getInt("stu_no"),
rs.getString("stu_name"),
rs.getString("stu_sex"),
rs.getInt("stu_age"),
rs.getString("stu_birth"));
list.add(stuEnt);
};
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
new Dbutil().closeDb(null, ps, conn);
}
return list;
}
@Override
public int countRow(Map<String, Object> map) {
// TODO Auto-generated method stub
Dbutil db=new Dbutil();
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
int retNum=0;
String sql="select count(stu_no) from students";
conn=db.getConnection();
try {
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
retNum=rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
db.closeDb(rs, ps, conn);
}
return retNum;
}
@Override
public PageModel<Students> queryPage(Map<String, Object> map) {
// TODO Auto-generated method stub
PageModel<Students> pm=new PageModel<Students>();
int size=Integer.parseInt(map.get("size")+"");
int currPage=Integer.parseInt(map.get("currentPage")+"");
//赋值每页查询的条数
pm.setSize(size);
//计算当前是多少页
pm.setCurrentPage(currPage);
//计算总页数
pm.setSumcount(this.countRow(map));
//调用方法
String sql="select * from students limit "+(currPage-1)*size+","+size;
ArrayList<Students> list=this.arrayList(sql);
pm.setList(list);
return pm;
}
/*分页查询*/
public ArrayList<Students> arrayList(String sql){
ArrayList<Students> list=new ArrayList<Students>();
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
conn=new Dbutil().getConnection();
try {
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
Students stu=new Students( rs.getInt("stu_no"),
rs.getString("stu_name"),
rs.getString("stu_sex"),
rs.getInt("stu_age"),
rs.getString("stu_birth"));
list.add(stu);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
new Dbutil().closeDb(rs, ps, conn);
}
return list;
}
public ArrayList<Students> listUi(Map<String, Object> map){
ArrayList<Students> list=new ArrayList<Students>();
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
int size=Integer.parseInt(map.get("limitNum")+"");
int currPage=Integer.parseInt(map.get("page")+"");
String sql="select * from students limit "+(currPage-1)*size+","+size;
conn=new Dbutil().getConnection();
try {
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
Students stu=new Students( rs.getInt("stu_no"),
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java web数据交互+layui.zip (144个子文件)
Istudent.class 9KB
Stuservlet.class 8KB
PageModel.class 2KB
Dbutil.class 2KB
Students.class 2KB
Impstudent.class 1KB
.classpath 1KB
org.eclipse.wst.common.component 489B
org.eclipse.wst.jsdt.ui.superType.container 49B
layui.css 71KB
layer.css 14KB
layui.mobile.css 10KB
laydate.css 7KB
code.css 1KB
iconfont.eot 41KB
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
4.gif 6KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
41.gif 4KB
38.gif 4KB
65.gif 3KB
32.gif 3KB
45.gif 3KB
7.gif 3KB
12.gif 3KB
26.gif 3KB
60.gif 3KB
2.gif 3KB
40.gif 3KB
25.gif 3KB
19.gif 3KB
66.gif 3KB
18.gif 3KB
46.gif 3KB
10.gif 3KB
28.gif 3KB
51.gif 3KB
57.gif 3KB
67.gif 3KB
0.gif 3KB
48.gif 3KB
43.gif 3KB
30.gif 2KB
61.gif 2KB
33.gif 2KB
69.gif 2KB
14.gif 2KB
47.gif 2KB
36.gif 2KB
49.gif 2KB
58.gif 2KB
6.gif 2KB
54.gif 2KB
53.gif 2KB
56.gif 2KB
62.gif 2KB
31.gif 2KB
55.gif 2KB
35.gif 2KB
15.gif 2KB
loading-2.gif 2KB
37.gif 1KB
68.gif 1KB
52.gif 777B
loading-1.gif 701B
mysql-connector-java-8.0.13.jar 2.03MB
gson-2.8.5.jar 236KB
Istudent.java 8KB
Stuservlet.java 8KB
Students.java 1KB
PageModel.java 1KB
Dbutil.java 1KB
Impstudent.java 860B
jquery.easyui.min.js 447KB
layui.all.js 271KB
共 144 条
- 1
- 2
资源评论
素慔636
- 粉丝: 1
- 资源: 27
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于yolov5识别算法实现的DNF自动脚本源码.zip
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功