如何获得此方法的值

时间:2012-05-15 08:01:05

标签: java

我有一个使用数据库的项目,我有一些主要的类,如学生,模块,注册和更多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中我的构造函数是

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

因此在类EnrolmentManager中,它有一个错误,即构造函数Enrollment是unifined。你能解决这个问题吗,谢谢

2 个答案:

答案 0 :(得分:1)

注册类构造函数期待Studentstu)& Module个对象(module)作为参数,但是您将它们解析为String个对象。

答案 1 :(得分:0)

这是因为您的注册类期望Module和Student作为您提供2个字符串的参数。

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

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

但你传递的是

public Enrolment(String stu, String module,Double internalMark, Double examMark)