package dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import bean.Student;
public class studentDao{
public int addStudent(String studentId,String studentName,String classname,String sex) throws Exception{
Connection con =null;
PreparedStatement ps = null;
ResultSet rs = null;
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=School";
String userName="sa";
String userPwd="123";
int count = 0;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "insert into T_student values(?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, studentId);
ps.setString(2,studentName);
ps.setString(3,sex);
ps.setString(4,classname);
count = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
finally {
try {// 关闭连接
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
} catch (Exception e) {
}
}
return count;
}
public int delStudent(String studentId) throws Exception{
Connection con =null;
PreparedStatement ps = null;
ResultSet rs = null;
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=School";
String userName="sa";
String userPwd="123";
int count = 0;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "DELETE FROM T_student WHERE studentId = ? ";
ps = con.prepareStatement(sql);
ps.setString(1,studentId);
count = ps.executeUpdate();
} catch (Exception e) {}
finally {
try {// 关闭连接
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
} catch (Exception e) {
}
}
return count;
}
public int altStudent(String studentId,String xg,String x) throws Exception{
Connection con =null;
PreparedStatement ps = null;
ResultSet rs = null;
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=School";
String userName="sa";
String userPwd="123";
int count = 0;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "update T_student set ? = ? where studentId = ?";
ps = con.prepareStatement(sql);
ps.setString(1,xg);
ps.setString(2,x);
ps.setString(3,studentId);
count = ps.executeUpdate();
} catch (Exception e) {}
finally {
try {// 关闭连接
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
} catch (Exception e) {
}
}
return count;
}
public List queStudent(String studentId) throws Exception{
Connection con =null;
PreparedStatement ps = null;
ResultSet rs = null;
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=School";
String userName="sa";
String userPwd="123";
List list = new ArrayList();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "SELECT * FROM T_student WHERE studentId = ? ";
ps = con.prepareStatement(sql);
ps.setString(1,studentId);
rs = ps.executeQuery();
if(rs.next()){
Student student = new Student();
student.setClassname(rs.getString("classname"));
student.setStudentId(rs.getString("studentId"));
student.setSex(rs.getString("sex"));
student.setStudentName(rs.getString("studentName"));
list.add(student);
}
} catch (Exception e) {}
finally {
try {// 关闭连接
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
} catch (Exception e) {
}
}
return list;
}
public int passwordyz(String studentId) throws Exception{
Connection con =null;
PreparedStatement ps = null;
ResultSet rs = null;
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=School";
String userName="sa";
String userPwd="123";
int count = 0;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "SELECT * FROM T_student WHERE studentId = ?";
ps = con.prepareStatement(sql);
ps.setString(1,studentId);
rs = ps.executeQuery();
while(rs.next()){
count++;
}
} catch (Exception e) {}
finally {
try {// 关闭连接
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
} catch (Exception e) {
}
}
return count;
}
public List allStudent() throws Exception{
Connection con =null;
PreparedStatement ps = null;
ResultSet rs = null;
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=School";
String userName="sa";
String userPwd="123";
List list = new ArrayList();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "SELECT * FROM T_student";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
Student student = new Student();
student.setClassname(rs.getString("classname"));
student.setStudentId(rs.getString("studentId"));
student.setSex(rs.getString("sex"));
student.setStudentName(rs.getString("studentName"));
list.add(student);
}
} catch (Exception e) {}
finally {
try {// 关闭连接
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
} catch (Exception e) {
}
}
return list;
}
public List teaStudent(String courseId) throws Exception{
Connection con =null;
PreparedStatement ps = null;
ResultSet rs = null;
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=School";
String userName="sa";
String userPwd="123";
List list = new ArrayList();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "SELECT * FROM T_student,T_xuanke where T_student.studentId=T_xuanke.studentId and T_xuanke.courseId= ?";
ps = con.prepareStatement(sql);
ps.setString(1,courseId);
rs = ps.executeQuery();
while(rs.next()){
Student student = new Student();
student.setClassname(rs.getString("classname"));
student.setStudentId(rs.getString("studentId"));
student.setSex(rs.getString("sex"));
student.setStudentName(rs.getString("studentName"));
list.add(student);
}
} catch (Exception e) {}
finally {
try {// 关闭连接
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
} catch (Exception e) {
}
}
return list;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
jsp写的学生考勤信息系统,可用于毕业设计,平时上课完成作业。(SP(全称JavaServer Pages)是由Sun Microsystems公司主导创建的一种动态网页技术标准。JSP部署于网络服务器上,可以响应客户端发送的请求,并根据请求内容动态地生成HTML、XML或其他格式文档的Web网页,然后返回给请求者。JSP技术以Java语言作为脚本语言,为用户的HTTP请求提供服务,并能与服务器上的其它Java程序共同处理复杂的业务需求)
资源推荐
资源详情
资源评论
















收起资源包目录


















































































共 60 条
- 1
资源评论

- 宽�2021-07-10感觉内容不全

ConeyLa
- 粉丝: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- (源码)基于Go语言框架的订单管理系统.zip
- 浙江省高校一级计算机等级考试理论部分参考题总汇.doc
- 人工智能时代下的计算机网络安全的风险控制策略研究.docx
- 算法分析与设计d讲.doc
- VB酒店服务管理系统.doc
- VB图书管理完整论文.doc
- 探析信息发展下的计算机网络与经济的关系.docx
- 单片机控制的花样彩灯设计.doc
- Linux攻略DNS服务器安装配置方法详细介绍.doc
- 氨合成催化剂类翻英技术文件翻译网站及中英对照.doc
- 【传统网络营销】网站推广现状分析及推广方法介绍.doc
- (源码)基于Arduino微控制器的VNT15发动机控制器项目.zip
- 论述5G无线通信场景需求与技术演进.docx
- 项目管理进度跟踪表(DOC格式).doc
- 基于大数据的高校教务管理平台设计.docx
- 室内高精度融合定位在工业物联网的应用.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
