• 大小: 4.32MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-17
  • 语言: Java
  • 标签: Java  IDEA  JavaWeb  JSP  

资源简介

用IDEA开发的JavaWeb简易作业管理系统,使用MySql数据库,内含建表语句。
功能实现如下:
老师:添加作业,添加学生,查看作业情况
学生:提交作业

资源截图

代码片段和文件信息

package com.java.code.Jdbc;

import com.java.code.Model.Homework;
import com.java.code.Model.Student;
import com.java.code.Model.StudentHomework;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class StudentHomeworkJdbc {

    public static void main(String[] args) {
        String a =“1“;
        List list = selectAll(a);
        for (StudentHomework sthw : list){
            System.out.println(sthw.gethwId());
        }
        Homework hw = showHomeworkDetails(a);
        System.out.println(hw.gethwtitle());
    }

    private static String url = “jdbc:mysql://127.0.0.1:3306/school?serverTimezone=Asia/Shanghai“;

    private static String driverName = “com.mysql.cj.jdbc.Driver“;


    /**
     * 从student_homework表读取指定作业id 的所有记录,即某次作业的所有提交记录
     * @return 返回结果list
     */
    public static List selectAll(String hw_id) {

        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        String sqlString = “SELECT * FROM student_homework where hw_id=“+hw_id;

        List list = new ArrayList<>();
        try (Connection connection = DriverManager.getConnection(url “root“ “12345ysp“)) {
            try (Statement statement = connection.createStatement()) {
                try (ResultSet resultSet = statement.executeQuery(sqlString)) {
                    //获取执行结果
                    while (resultSet.next()) {
                        StudentHomework sh = new StudentHomework();
                        sh.setsthwId(resultSet.getLong(“st_hw_id“));
                        sh.setstId(resultSet.getLong(“st_id“));
                        sh.sethwId(resultSet.getLong(“hw_id“));
                        sh.sethwtitle(resultSet.getString(“hw_title“));
                        sh.sethwContent(resultSet.getString(“hw_content“));
                        sh.setsubmitContent(resultSet.getString(“submit_content“));
                        sh.setsthwCreateTime(resultSet.getTimestamp(“st_hw_create_time“));
                        list.add(sh);
                    }
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }


    /**
     * 向homework表添加作业记录
     * @param homework  将要添加的homework
     * @return true=>成功否则失败
     */
    public static boolean addHomework(Homework homework){

        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        String sqlString = “insert into homework (hw_idhw_titlehw_contenthw_create_time) values(????)“;

        int resultSet = 0;
        try (Connection connection = DriverManager.getConnection(url “root“ “12345ysp“)) {
            try (PreparedStatement ps = connection.prepareStatement(sqlString)) {
         

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\artifacts\
     文件         563  2020-03-10 20:44  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\artifacts\JavaEE_HomeworkManager_war_exploded.xml
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\codestyles\
     文件         153  2020-03-10 20:44  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\codestyles\codestyleConfig.xml
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\libraries\
     文件         290  2020-03-10 20:46  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\libraries\lib.xml
     文件         276  2020-03-10 20:44  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\misc.xml
     文件         291  2020-03-10 20:44  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\modules.xml
     文件       10652  2020-03-10 22:41  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\.idea\workspace.xml
     文件        1000  2020-03-10 20:46  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\JavaEE-HomeworkManager.iml
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Jdbc\
     文件        9138  2020-03-10 22:34  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Jdbc\StudentHomeworkJdbc.class
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Model\
     文件        1283  2020-03-10 20:46  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Model\Homework.class
     文件        1083  2020-03-10 20:46  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Model\Student.class
     文件        1852  2020-03-10 20:46  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Model\StudentHomework.class
     目录           0  2020-03-10 22:49  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Servlet\
     文件        2088  2020-03-10 20:46  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Servlet\AddHomeworkServlet.class
     文件        2020  2020-03-10 20:46  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Servlet\AddStudentServlet.class
     文件        1598  2020-03-10 20:46  JavaWeb-HomeworkManager\JavaEE-HomeworkManager\out\artifacts\JavaEE_HomeworkManager_war_exploded\WEB-INF\classes\com\java\code\Servlet\QueryStudentHomeworkServlet.class
............此处省略67个文件信息

评论

共有 条评论