我在sql中有这些表:
create table courseDegree(code integer primary key, name varchar(20) not null)
create table course (code VARCHAR(10) , year INTEGER(4), name varchar(20), description varchar(100), primary key (code, year))
create table coursesForCourseDegree (courseDegreeCode integer, courseCode integer, courseYear numeric(4),
primary key (courseDegreeCode, courseYear, courseCode),
foreign key (courseDegreeCode) references courseDegree(code) on delete cascade on update cascade,
foreign key (courseCode, courseYear) references course(code, year) on
delete cascade on update cascade)
和这些行:
courseDegree有(2;"computer science")
课程有:("1info";2017;"C";"C for advanced programming")
和courseforCourseDegree has (1,"1info","2017")
我的功能是:
public List<String[]> courseNotInStudyPlan(String degreeCode, int enrollmentYear) throws SQLException
{
String sql="select * from course where (code, year) in (select courseCode, courseYear from courseForCourseDegree where courseDegreeCode=? and courseYear>=?)";
List<String[]> course=new ArrayList<>();
PreparedStatement prepStat = null;
try {
prepStat =conn.prepareStatement(sql);
prepStat.setString(1, degreeCode);
prepStat.setInt(2, enrollmentYear);
rs = prepStat.executeQuery();
} catch (SQLException e) {}
while (rs.next())
{
String code=rs.getString("code");
int year=rs.getInt("year");
String[] temp={code,String.valueOf(year)};
course.add(temp);
}
return course;
}
如果我在Postgres数据库中使用它,则此查询正在运行,但如果在我的Intellij中则不行。怎么了?
答案 0 :(得分:-1)
由于它不在IntelliJ编辑器中时工作,请检查Postgres db jar是否在IntelliJ类路径或lib目录中