小编典典

ResultSet来自UPDATE。没有数据

java

当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。没有数据。


阅读 276

收藏
2020-11-26

共1个答案

小编典典

这是不可能的,您必须将查询分开,以获得可以使用过程或函数的最佳解决方案。

  1. 程序应采取 lectureID
  2. 返回结果,在这种情况下,它应该是多个值,您可以阅读如何在mysql中从存储过程中检索多行?知道如何使用过程返回多个值
2020-11-26