package jdbc;
import model.Homework;
import model.Student;
import model.StudentHomework;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* @Author:txy
* @Date:created in 8:50 2020/3/8
*/
public class HomeworkJdbc {
//老师布置作业
public static boolean addHomework(Homework th) throws ClassNotFoundException {
String url="jdbc:mysql://127.0.0.1:3306/school?serverTimezone=UTC";
String drivername = "com.mysql.cj.jdbc.Driver";
Class.forName(drivername);//可以省略
boolean isSuccess = true;
try (Connection connection = DatabasePool.getHikariDataSource().getConnection()) {
//Preparestatement (增、删、改、查)
String sqlString = "insert into homework(id,title,content,create_time) values (?,?,?,?)";
PreparedStatement ps = connection.prepareStatement(sqlString);
ps.setLong(1,th.getId());
ps.setString(2,th.getTitle());
ps.setString(3,th.getContent());
ps.setTimestamp(4, th.getCreateTime());
//成功返回false 失败返回true
isSuccess = ps.execute();
} catch (SQLException e) {
e.printStackTrace();
}
//返回相反的结果
return !isSuccess;
}
//查询所有学生提交的作业
public static List<StudentHomework> selectAllStudentHomework() throws ClassNotFoundException {
String url="jdbc:mysql://127.0.0.1:3306/school?serverTimezone=UTC";
String drivername = "com.mysql.cj.jdbc.Driver";
String sqlString = "select * from student_homework ";
List<StudentHomework>list=new ArrayList<>();
Class.forName(drivername);//可以省略
try (Connection connection = DatabasePool.getHikariDataSource().getConnection()) {
//通过连接获取statement
try (Statement statement = connection.createStatement()) {
//statement (增、删、改、查)
try (ResultSet resultSet = statement.executeQuery(sqlString)) {
//获取执行结果
while (resultSet.next()) {
StudentHomework sh = new StudentHomework();
sh.setId(resultSet.getLong("id"));
sh.setStudentId(resultSet.getLong("student_id"));
sh.setHomeworkId(resultSet.getLong("homework_id"));
sh.setHomeworkTitle(resultSet.getString("homework_title"));
sh.setHomeworkContent(resultSet.getString("homework_content"));
sh.setCreateTime(resultSet.getTimestamp("create_time"));
sh.setUpdateTime(resultSet.getTimestamp("update_time"));
list.add(sh);
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
//查询所有教师布置的作业
public static List<Homework> selectAllTeacherHomework() throws ClassNotFoundException {
String url="jdbc:mysql://127.0.0.1:3306/school?serverTimezone=UTC";
String drivername = "com.mysql.cj.jdbc.Driver";
String sqlString = "select * from homework ";
List<Homework>list=new ArrayList<>();
Class.forName(drivername);//可以省略
try (Connection connection = DatabasePool.getHikariDataSource().getConnection()) {
//通过连接获取statement
try (Statement statement = connection.createStatement()) {
//statement (增、删、改、查)
try (ResultSet resultSet = statement.executeQuery(sqlString)) {
//获取执行结果
while (resultSet.next()) {
Homework th = new Homework();
th.setId(resultSet.getLong("id"));
th.setTitle(resultSet.getString("title"));
th.setContent(resultSet.getString("content"));
th.setCreateTime(resultSet.getTimestamp("create_time"));
th.setUpdateTime(resultSet.getTimestamp("update_time"));
list.add(th);
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
//查询某位学生提交的作业
public static List<StudentHomework> selectAStudentHomework(Long student_id) throws ClassNotFoundException {
String url="jdbc:mysql://127.0.0.1:3306/school?serverTimezone=UTC";
String drivername = "com.mysql.cj.jdbc.Driver";
String sqlString = "select * from student_homework where student_id="+student_id;
List<StudentHomework>list=new ArrayList<>();
Class.forName(drivername);//可以省略
try (Connection connection = DatabasePool.getHikariDataSource().getConnection()) {
//通过连接获取statement
try (Statement statement = connection.createStatement()) {
//statement (增、删、改、查)
try (ResultSet resultSet = statement.executeQuery(sqlString)) {
//获取执行结果
while (resultSet.next()) {
StudentHomework sh = new StudentHomework();
sh.setId(resultSet.getLong("id"));
sh.setStudentId(resultSet.getLong("student_id"));
sh.setHomeworkId(resultSet.getLong("homework_id"));
sh.setHomeworkTitle(resultSet.getString("homework_title"));
sh.setHomeworkContent(resultSet.getString("homework_content"));
sh.setCreateTime(resultSet.getTimestamp("create_time"));
sh.setUpdateTime(resultSet.getTimestamp("update_time"));
list.add(sh);
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
//查询某次作业的提交情况
public static List<StudentHomework> selectAHomework(Long homework_id) throws ClassNotFoundException {
String url="jdbc:mysql://127.0.0.1:3306/school?serverTimezone=UTC";
String drivername = "com.mysql.cj.jdbc.Driver";
String sqlString = "select * from student_homework where homework_id="+homework_id;
List<StudentHomework>list=new ArrayList<>();
Class.forName(drivername);//可以省略
try (Connection connection = DatabasePool.getHikariDataSource().getConnection()) {
//通过连接获取statement
try (Statement statement = connection.createStatement()) {
//statement (增、删、改、查)
try (ResultSet resultSet = statement.executeQuery(sqlString)) {
//获取执行结果
while (resultSet.next()) {
StudentHomework sh = new StudentHomework();
sh.setId(resultSet.getLong("id"));
sh.setStudentId(resultSet.getLong("student_id"));
sh.setHomeworkId(resultSet.getLong("homework_id"));
sh.setHomeworkTitle(resultSet.getString("homework_title"));
sh.setHomeworkContent(resultSet.getString("homework_content"));
sh.setCreateTime(resultSet.getTimestamp("create_time"));
sh.setUpdateTime(resultSet.getTimestamp("update_time"));
list.add(sh);
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
//学生提交作业
public static String handHomework(StudentHomework sh) throws ClassNotFoundException {
String ur
没有合适的资源?快使用搜索试试~ 我知道了~
基于maven+jsp+servlet+mysql+java的作业管理系统.zip
共95个文件
class:33个
java:21个
jar:14个
需积分: 1 1 下载量 4 浏览量
2024-06-15
19:29:38
上传
评论
收藏 6.99MB ZIP 举报
温馨提示
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
资源推荐
资源详情
资源评论
收起资源包目录
基于maven+jsp+servlet+mysql+java的作业管理系统.zip (95个子文件)
ori_code_vip
lib
javax.jms.jar 25KB
javax.annotation.jar 8KB
javax.transaction.jar 9KB
javax.servlet.jsp.jar 77KB
javax.persistence.jar 127KB
javax.servlet.jar 68KB
javax.ejb.jar 46KB
javax.servlet.jsp.jstl.jar 27KB
javax.resource.jar 43KB
pom.xml 793B
web
pom.xml 3KB
src
main
java
org
example
controller
servlet
Test_Servlet.java 728B
TeacherAddStudentServlet.java 2KB
TeacherAddHomeworkServlet.java 3KB
TeacherSearchAStudentHWServlet.java 1KB
TeacherSearchStudentServlet.java 954B
StudentAddHomeworkServlet.java 2KB
TeacherSearchShServlet.java 1022B
StudentHandInHomeworkServlet.java 646B
Test_Servlet_V3.java 932B
TeacherHomeworkServlet.java 989B
TeacherSearchAHWSubmitStatusServlet.java 1KB
Test_Servlet_V2.java 844B
webapp
WEB-INF
lib
mysql-connector-java-8.0.16.jar 2.19MB
web.xml 215B
index.jsp 765B
Tea_Add_Student.jsp 1KB
AStudentHW.jsp 1KB
Stu_HandIn_HW.jsp 813B
Tea_Add_HW.jsp 2KB
Tea_Query_HW.jsp 3KB
target
classes
org
example
controller
servlet
TeacherSearchAStudentHWServlet.class 2KB
Test_Servlet_V3.class 2KB
TeacherSearchShServlet.class 2KB
Test_Servlet.class 1KB
TeacherSearchStudentServlet.class 2KB
StudentHandInHomeworkServlet.class 1KB
StudentAddHomeworkServlet.class 3KB
TeacherHomeworkServlet.class 2KB
TeacherSearchAHWSubmitStatusServlet.class 2KB
Test_Servlet_V2.class 1KB
TeacherAddStudentServlet.class 3KB
TeacherAddHomeworkServlet.class 3KB
web
WEB-INF
classes
org
example
controller
servlet
TeacherSearchAStudentHWServlet.class 2KB
Test_Servlet_V3.class 2KB
TeacherSearchShServlet.class 2KB
Test_Servlet.class 1KB
TeacherSearchStudentServlet.class 2KB
StudentHandInHomeworkServlet.class 1KB
StudentAddHomeworkServlet.class 3KB
TeacherHomeworkServlet.class 2KB
TeacherSearchAHWSubmitStatusServlet.class 2KB
Test_Servlet_V2.class 1KB
TeacherAddStudentServlet.class 3KB
TeacherAddHomeworkServlet.class 3KB
lib
slf4j-api-1.7.25.jar 40KB
mysql-connector-java-8.0.16.jar 2.19MB
db-1.0-SNAPSHOT.jar 13KB
HikariCP-3.4.2.jar 149KB
web.xml 215B
index.jsp 765B
Tea_Add_Student.jsp 1KB
AStudentHW.jsp 1KB
Stu_HandIn_HW.jsp 813B
Tea_Add_HW.jsp 2KB
META-INF
MANIFEST.MF 96B
Tea_Query_HW.jsp 3KB
web.war 2.27MB
.idea
libraries
Java_EE_6_Java_EE_6.xml 775B
vcs.xml 172B
misc.xml 658B
compiler.xml 598B
.gitignore 39B
encodings.xml 195B
core
pom.xml 544B
Homework_Managment_System.iml 81B
db
pom.xml 1KB
src
main
java
model
Homework.java 1012B
StudentHomework.java 1KB
Student.java 828B
jdbc
Test_jdbc.java 1KB
StudentJdbc.java 3KB
HomeworkJdbc.java 10KB
Test_jdbc_v3.java 1KB
DatabasePool.java 1021B
Test_jdbc_v2.java 2KB
target
classes
model
Homework.class 1KB
StudentHomework.class 2KB
Student.class 1KB
jdbc
StudentJdbc.class 4KB
Test_jdbc_v3.class 2KB
Test_jdbc_v2.class 3KB
Test_jdbc.class 2KB
HomeworkJdbc.class 9KB
DatabasePool.class 1KB
共 95 条
- 1
资源评论
毕业小助手
- 粉丝: 2764
- 资源: 5583
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 电子学习资料基础资料数字逻辑电路计数器
- 模板文档开发与应用基础教程
- 电子学习资料基础资料循环彩灯
- 自动作业平台sw18可编辑全套技术资料100%好用.zip.zip
- 电子学习资料基础资料有线对讲机电路图
- 电子学习资料基础资料远距离调频无线话筒
- 电子学习资料基础资料智能电力线载波电话系统
- 电子学习资料基础资料自激多谐振荡器闪光灯
- 电子学习资料基础资料电感线圈的简易制作
- 电子学习资料基础资料手机充电器电路原理图及充电器的安全标准
- 电子学习资料基础资料数字放大器
- 电子学习资料STM32开发板例程(库函数版本)
- 电子学习资料数字电子系统设计(CPLD)
- 电子学习资料数字教师手册辅导教学使用
- uniapp项目实战教程含源码多端合一SpringBoot2.X+Vue+UniAPP全栈开发医疗小程序
- uniapp项目实战教程含源码多端合一uni-app+springboot实战某音短视频app
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功