当executeQuery函数运行,sql语句正常工作并在sql编辑器上运行时,给出正确的结果时,会发生问题。当它在jdbc上运行时,不会执行。该连接接受多个查询。
String query = "set @countOfLectureGrade = (SELECT Count(goc.Affect) FROM GradeOfCourse goc WHERE goc.LectureID = ?);" + "SELECT u.SchoolID, u.Name, u.Surname, u.Role, u.Email, " + "CASE WHEN @countOfLecture = 0 then 0 " + "ELSE AVG(0.01 * goc.Affect * gos.Grade) " + "END AS Average " + "FROM GradeOfCourse goc, GradeOfStudent gos, User u, CourseOfStudent cos " + "WHERE " + "(gos.CourseGradeID = goc.GradeID AND u.SchoolID = gos.StudentID AND goc.LectureID = ?) " + "OR (u.SchoolID = cos.SchoolID AND cos.LectureID = ? AND @countOfLectureGrade = 0) " + "GROUP BY u.SchoolID;"; try { connection = super.getConnection(); PreparedStatement sqlStatement = connection.prepareStatement(query); sqlStatement.setInt(1, lectureID); sqlStatement.setInt(2, lectureID); sqlStatement.setInt(3, lectureID); ResultSet resultSet = sqlStatement.executeQuery();
java.sql.SQLException:ResultSet来自UPDATE。没有数据。
这是不可能的,您必须将查询分开,以获得可以使用过程或函数的最佳解决方案。
lectureID