IDEA+Java+JSP+Mysql+Tomcat实现Web教师信息管理系统(1)

本文档展示了如何使用IntelliJ IDEA、Java、JSP、MySQL和Tomcat构建一个Web教师信息管理系统。内容包括教师列表、新增、修改和删除教师的功能。系统通过数据库操作类实现对教师信息的CRUD操作,JSP页面用于用户交互。
摘要由CSDN通过智能技术生成

// 4.保存查询出来的数据到list

List list = new ArrayList<>();

while (rs.next()) {

Teacher teacher = new Teacher();

teacher.setId(rs.getInt(“id”));

teacher.setName(rs.getString(“name”));

teacher.setSex(rs.getString(“sex”));

teacher.setSubject(rs.getString(“subject”));

teacher.setSalary(rs.getDouble(“salary”));

teacher.setWorkTime(rs.getString(“workTime”));

list.add(teacher);

}

return list;

} catch (Exception e) {

e.printStackTrace();

} finally {

// 关闭链接,避免数据库连接过多

DBUtil.close(con, ps, rs);

}

return null;

}

/**

  • 根据教职工号查询教师信息

  • @param id

  • @return

*/

@Override

public Teacher selectTeacher(Integer id) {

Connection con = null;

PreparedStatement ps = null;

ResultSet rs = null;

try {

// 1.连接数据库

con = DBUtil.getConnection();

// 2.预编译

String sql = “select * from Teacher where id = ?”;

ps = con.prepareStatement(sql);

ps.setInt(1,id);

// 3.执行sql

rs = ps.executeQuery();

while (rs.next()){

Teacher teacher = new Teacher();

teacher.setId(rs.getInt(“id”));

teacher.setName(rs.getString(“name”));

teacher.setSex(rs.getString(“sex”));

teacher.setSubject(rs.getString(“subject”));

teacher.setSalary(rs.getDouble(“salary”));

teacher.setWorkTime(rs.getString(“workTime”));

return teacher;

}

} catch (ClassNotFoundException e) {

e.printStackTrace();

} catch (SQLException e) {

e.printStackTrace();

}finally {

// 关闭资源,避免出现异常

DBUtil.close(con,ps,rs);

}

return null;

}

/**

  • 新增教师信息

  • @param teacher

  • @return

*/

@Override

public boolean addTeacher(Teacher teacher) {

String sql = “insert into teacher values (?,?,?,?,?,?)”;

List list = new ArrayList();

list.add(teacher.getId());

list.add(teacher.getName());

list.add(teacher.getSex());

list.add(teacher.getSubject());

list.add(teacher.getSalary());

list.add(teacher.getWorkTime());

boolean flag = DBUtil.addUpdateDelete(sql,list.toArray());

if(flag){

return true;

}else {

return false;

}

}

/**

  • 更新教师信息

  • @param teacher

  • @return

*/

@Override

public boolean updateTeacher(Teacher teacher) {

String sql = “update teacher set name=?,sex=?,subject=?,salary=?,workTime=? where id=?”;

List list = new ArrayList();

list.add(teacher.getName());<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值