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币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于C++实现二叉树的创建,遍历,添加,查找与删除
- 基于C语言实现二叉树的基本操作
- 毕业设计基于STM32的测量温度与压力的数据处理设计C语言完整源码+论文.zip
- 基于MATLAB的PCA算法人脸识别项目源码+GUI界面+说明文档.zip
- 基于STM32的测量温度与压力的数据处理设计源码+论文(毕业设计).zip
- Vision Transformer 网络对不同氨气氧气浓度轨迹RAS 图像数据集的分类,包含训练权重和数据集、迁移学习
- 基于C51带字库LCD12864(ST7920)的keil工程源码,只支持8位并口通讯(不支持串口),可显示中文.zip
- 基于SI4463射频模块433MD-SMA无线模块软硬件技术资料及(SI4463)IC技术资料文档.zip
- (GPS+北斗+GSM)HLK-GS2503模块软硬件开发资料包硬件参考设计(原理图PCB)+技术文档资料.zip
- 基于BERT+Biaffine结构的关系抽取模型源码+文档说明.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功