-1

我有一个使用数据库的项目,我有一些主要课程,如学生、模块、招生和更多 3 个课程来管理它们。这里的问题是

在学生班我有这个代码

私有字符串 id;

@DomainConstraint(optional = false, mutable = true, type = Type.String, length = 50)
private String name;

@DomainConstraint(optional = false, mutable = true, type = Type.String, length = 20)
private String dob;

@DomainConstraint(optional = false, mutable = true, type = Type.String, length = 50)
private String address;

@DomainConstraint(optional = false, mutable = true, type = Type.String, length = 50)
private String email;

private static int autoIncrementInt = 0;

public Student(String name, String dob, String address, String email) {
    this.name = name;
    this.dob = dob;
    this.address = address;
    this.email = email;
    idGenerator();
}

但是在班级 EnrolmentManager 中,我想以学生的名义为他们注册这样的课程

public void load() throws SQLException {
    Connection con;
    Properties connectionProps = new Properties();
    // set up properties, e.g. user name/password
    con = DriverManager.getConnection("jdbc:derby:courseman;create=false", connectionProps);
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT Student.name as studentName, Module.name as Modulename, Enrolment.internalMark,Enrolment.examMark FROM Student,Module,Enrolment WHERE Student.id=Enrolment.sid AND Module.code=Enrolment.mcode");

    while (rs.next()) {
        String s = rs.getString("studentName");
        String m = rs.getString("Modulename");
        double y = rs.getDouble("internalMark");
        double d = rs.getDouble("examMark");
        Enrolment e = new Enrolment( s, m, y, d);
        enrolments.add(e);
    }
}

这里有一个错误,因为在类 Enrollment 我有它的 Constructor 是

public Enrolment(Student stu, Module module,Double internalMark, Double examMark) {
    this.student = stu;
    this.module = module;
    this.internalMark = internalMark;
    this.examMark = examMark;
    finalGradeGenerator();
}

因此在类中EnrolmentManager,它有一个错误是构造函数注册是未定义的。你能帮我解决这个问题吗,谢谢

4

2 回答 2

1

注册类构造函数期望Student( stu) 和Module对象 ( module) 作为参数,但是您将它们解析为String对象。

于 2012-05-15T08:05:28.630 回答
0

这是因为您的注册课程期望 Module 和 Student 作为您提供 2 Strings 的参数。

//下面是实际的构造函数

public Enrolment(Student stu, Module module,Double internalMark, Double examMark) 

但你正在传递

public Enrolment(String stu, String module,Double internalMark, Double examMark)
于 2012-05-15T08:06:18.693 回答