package cn.edu.thsis.dao.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.sun.corba.se.impl.orb.ParserTable.TestAcceptor1;
import cn.edu.thsis.dao.UserDao;
import cn.edu.thsis.pojo.User;
import cn.edu.thsis.pojo.student;
import cn.edu.thsis.pojo.teacher;
import cn.edu.thsis.pojo.thsis;
public class UserDaoImpl extends BaseDao implements UserDao{
//根据用户名和密码查询用户信息
@Override
public User chexkUserLoginDao(String uid, String pwd, String type) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
User u = null;
try {
conn = jdbcUtils.getConnection();
String sql = "select * from "+type+" where uid=? and pwd=?";
ps=conn.prepareStatement(sql);
ps.setString(1,uid);
ps.setString(2,pwd);
rs=ps.executeQuery();
while (rs.next()) {
u=new User();
u.setUid(rs.getString("uid"));
u.setUname(rs.getString("uname"));
u.setPwd(rs.getString("pwd"));
}
} catch (Exception e) {
e.printStackTrace();
}finally {
//关闭资源
if(rs != null) rs.close();
if(ps != null) ps.close();
if(conn != null) conn.close();
}
//返回结果
return u;
}
@Override
public User findUserDao(String uid, String type) throws SQLException {
//声明jdbc对象
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
//声明变量
student stu = null;
teacher tea = null;
try {
conn = jdbcUtils.getConnection();
//创建sql命令
String sql = "select * from "+type+" where uid=?";
//创建sql命令对象
ps=conn.prepareStatement(sql);
//给占位符赋值
ps.setString(1, uid);
//执行sql
rs=ps.executeQuery();
//遍历结果
if (type.equals("student")) {
while (rs.next()) {
//给变量赋值
stu=new student();
stu.setUid(rs.getString("uid"));
stu.setUname(rs.getString("uname"));
stu.setPwd(rs.getString("pwd"));
stu.setMajor(rs.getString("major"));
stu.setStu_tel(rs.getString("stu_tel"));
stu.setStu_email(rs.getString("stu_email"));
}
}else {
tea=new teacher();
tea.setUid(rs.getString("uid"));
tea.setUname(rs.getString("uname"));
tea.setPwd(rs.getString("pwd"));
tea.setTea_title(rs.getString("tea_title"));
tea.setTea_tel(rs.getString("tea_tel"));
}
} catch (Exception e) {
e.printStackTrace();
}finally {
//关闭资源
rs.close();
ps.close();
conn.close();
}
//返回结果
if (type.equals("student")) {
return stu;
}else {
return tea;
}
}
//根据用户ID修改用户密码
@Override
public int userChangePwdDao(String newPwd, String uid ,String type) throws SQLException {
//声明jdbc对象
Connection conn = null;
PreparedStatement ps = null;
//创建变量
int index = -1;
//加载驱动
try {
conn = jdbcUtils.getConnection();
//创建sql命令
String sql = "update "+type+" set pwd=? where uid=?";
//创建SQL命令对象
ps = conn.prepareStatement(sql);
//给占位符赋值
ps.setString(1,newPwd);
ps.setString(2,uid);
//执行
index = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}finally {//关闭资源
ps.close();
conn.close();
}
//返回结果
return index;
}
//获取老师信息
public List<teacher> teaShowDao() throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<teacher> tealist =null;
try {
conn = jdbcUtils.getConnection();
String sql = "select * from teacher";
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
tealist = new ArrayList<teacher>();
while (rs.next()) {
User tea=new teacher();
tea.setUid(rs.getString("uid"));
tea.setUname(rs.getString("uname"));
((teacher) tea).setTea_title(rs.getString("tea_title"));
((teacher) tea).setTea_tel(rs.getString("tea_tel"));
tealist.add((teacher) tea);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
rs.close();
ps.close();
conn.close();
}
return tealist;
}
//添加教师信息
@Override
public int addteaDao(teacher teahr) {
Connection conn = null;
PreparedStatement ps = null;
int index = -1;
try {
conn = jdbcUtils.getConnection();
String sql = "insert into teacher values(?,?,default,?,?,default)";
ps = conn.prepareStatement(sql);
ps.setString(1, teahr.getUid());
ps.setString(2,teahr.getUname());
ps.setString(3,teahr.getTea_title());
ps.setString(4,teahr.getTea_tel());
index=ps.executeUpdate();
ps.close();
}catch (Exception e) {
e.printStackTrace();
}finally {
//关闭资源
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
//返回结果
return index;
}
//添加学生信息
@Override
public int addstuDao(student stud) {
Connection conn = null;
PreparedStatement ps = null;
int index = -1;
try {
conn = jdbcUtils.getConnection();
String sql = "insert into student values(?,?,default,?,?,?,default)";
ps = conn.prepareStatement(sql);
ps.setString(1,stud.getUid());
ps.setString(2,stud.getUname());
ps.setString(3,stud.getMajor());
ps.setString(4,stud.getStu_tel());
ps.setString(5,stud.getStu_email());
index=ps.executeUpdate();
ps.close();
}catch (Exception e) {
e.printStackTrace();
}finally {
//关闭资源
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
//返回结果
return index;
}
//获取学生信息
@Override
public List<student> stuShowDao() throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<student> stulist =null;
try {
conn = jdbcUtils.getConnection();
String sql = "select * from student";
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
stulist = new ArrayList<student>();
while (rs.next()) {
User stu=new student();
stu.setUid(rs.getString("uid"));
stu.setUname(rs.getString("uname"));
((student) stu).setMajor(rs.getString("major"));
((student) stu).setStu_tel(rs.getString("stu_tel"));
((student) stu).setStu_email(rs.getString("stu_email"));
stulist.add((student) stu);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
//关闭资源
rs.close();
ps.close();
conn.close();
}
//返回结果
return stulist;
}
//删除教师信息
@Override
public int delteaDao(String uid) throws SQLException {
int index =0;
String sql = "delete from teacher where uid='"+uid+"'";
Connection conn =jdbcUtils.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
index = ps.executeUpdate();
return index;
}
//删除学生信息
@Override
public int delstuDao(String uid) throws SQLException {
int index =0;
String sql = "delete from student where uid='"+uid+"'";
Connection conn =jdbcUtils.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
index = ps.executeUpdate();
return index;
}
//学生预约注册论题
@Override
public int doEnrolDao(String thsis_id, String stu_id) throws SQLException {
int index = 0;
String sql = "insert into enrol(stu_id,thsis_id) values('"+stu_id+"','"+thsis_id+"')";
Connection conn = jdbcUtils.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
index = ps.executeUpdate();
return index;
}
//判断学生是否已预约该论题
public boolean hasLogin(String stu_id,String thsis_id) throws SQLException {
boolean f = false;
String sql = "SELECT en.stu_id,en.thsis_id from enrol en WHERE en.stu_id='"+stu_id+"' AND
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
环境:开发工具:idea,数据库:MySQL5.7 jdk1.8 架构:Javaweb,前端jsp 主要功能 管理员:公告管理、教师管理、学生管理、论文管理 教师:添加论文、我的论文、学生信息、所有论文、消息管理 学生: 个人资料、论文列表、论文动态、导师列表
资源推荐
资源详情
资源评论
收起资源包目录
毕设-基于JavaWeb毕业论文选题系统 (795个子文件)
UserDaoImpl.class 14KB
UserDaoImpl.class 14KB
UserDaoImpl.class 14KB
UpdateUserServlet.class 7KB
UpdateUserServlet.class 7KB
UpdateUserServlet.class 7KB
TeaSvlt.class 6KB
TeaSvlt.class 6KB
TeaSvlt.class 6KB
UserServlet.class 5KB
UserServlet.class 5KB
UserServlet.class 5KB
NewsInfoServlet.class 5KB
NewsInfoServlet.class 5KB
NewsInfoServlet.class 5KB
NewsInfoDaoImpl.class 4KB
NewsInfoDaoImpl.class 4KB
NewsInfoDaoImpl.class 4KB
UserServiceImpl.class 4KB
UserServiceImpl.class 4KB
UserServiceImpl.class 4KB
StuSvlt.class 3KB
StuSvlt.class 3KB
StuSvlt.class 3KB
thsis.class 3KB
thsis.class 3KB
thsis.class 3KB
BaseDao.class 2KB
BaseDao.class 2KB
BaseDao.class 2KB
NewsInfoServiceImpl.class 2KB
NewsInfoServiceImpl.class 2KB
NewsInfoServiceImpl.class 2KB
student.class 2KB
student.class 2KB
student.class 2KB
newsinfo.class 2KB
newsinfo.class 2KB
newsinfo.class 2KB
UserService.class 2KB
UserService.class 2KB
UserService.class 2KB
teacher.class 2KB
teacher.class 2KB
teacher.class 2KB
jdbcUtils.class 2KB
jdbcUtils.class 2KB
jdbcUtils.class 2KB
UserDao.class 1KB
UserDao.class 1KB
UserDao.class 1KB
mess.class 1KB
mess.class 1KB
mess.class 1KB
User.class 884B
User.class 884B
User.class 884B
NewsInfoService.class 570B
NewsInfoService.class 570B
NewsInfoService.class 570B
NewsInfoDao.class 517B
NewsInfoDao.class 517B
NewsInfoDao.class 517B
admin.class 276B
admin.class 276B
admin.class 276B
org.eclipse.wst.common.component 477B
org.eclipse.wst.jsdt.ui.superType.container 49B
summernote-bs3.css 143KB
summernote-bs3.css 143KB
style.css 133KB
style.css 133KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
animate.css 64KB
animate.css 64KB
datepicker3.css 33KB
datepicker3.css 33KB
font-awesome.css 32KB
font-awesome.css 32KB
bootstrap-rtl.css 31KB
bootstrap-rtl.css 31KB
font-awesome.min.css 26KB
font-awesome.min.css 26KB
ambiance.css 25KB
ambiance.css 25KB
style.min.css 25KB
style.min.css 25KB
sweetalert.css 18KB
sweetalert.css 18KB
simditor.css 17KB
simditor.css 17KB
ui.jqgrid.css 16KB
ui.jqgrid.css 16KB
jasny-bootstrap.min.css 14KB
jasny-bootstrap.min.css 14KB
jquery-ui-1.10.4.custom.min.css 14KB
jquery-ui-1.10.4.custom.min.css 14KB
共 795 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
计算机毕业设计,
- 粉丝: 554
- 资源: 110
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页