我正在尝试在Java中执行查询,但出现错误:方法executeQuery无法用于更新

这是错误跟踪:

com.ibm.db2.jcc.am.SqlException: [jcc][10103][10941][4.19.66] Method executeQuery cannot be used for update. ERRORCODE=-4476, SQLSTATE=null
at com.ibm.db2.jcc.am.kd.a(kd.java:731)
at com.ibm.db2.jcc.am.kd.a(kd.java:66)
at com.ibm.db2.jcc.am.kd.a(kd.java:128)
at com.ibm.db2.jcc.am.fp.a(fp.java:4433)
at com.ibm.db2.jcc.am.gp.b(gp.java:4179)
at com.ibm.db2.jcc.am.gp.lc(gp.java:768)
at com.ibm.db2.jcc.am.gp.executeQuery(gp.java:733)

这是我编写查询并返回查询字符串的Java代码:

public String createEventQuery() throws SQLException {
 StringBuilder eventQuery = new StringBuilder(500);
 eventQuery.append("SELECT ")
    .append("Student").append(".")
    .append(EventField.Roll_Num.name())
    .append(",").append("Student").append(".")
    .append(EventField.Name_Stud.name())
    .append(",").append("Student").append(".")
    .append(EventField.Class.name())
    .append(",").append("Teacher").append(".")
    .append(EventField.Name_Teach.name())
    .append(" FROM ")
    .append(Constants.STUDENT_TABLE).append(" AS Student")
    .append(" LEFT JOIN ")
    .append(Constants.Teacher_Table).append(" AS Teacher")
    .append(" ON Student.Class = Teacher.Class");
 return eventQuery.toString();
}  

我试图从我的方法之一调用查询:

PreparedStatement queryStatement ;
String myQuery;
myQuery = createQuery();
    try {
        queryStatement = dbConnection.prepareStatement(myQuery);
    } 
  ResultSet result = null;
    try {
        queryStatement.setString(1,timestamp);
        result = queryStatement.executeQuery();

    }
评论