如果参数值不正确,则无法执行查询

时间:2015-06-07 08:23:58

标签: java mysql

我有一个在本地数据库中工作正常的查询。我刚刚进入远程数据库,错误发生如下:

DAO:

public String changeLecture(String CoursesID, String strDate, String strTime, String endTime, String venue, NewCourseInfoBean courseInfo) {

      //preparing some objects for connection 
      Connection currentCon = null;
      ResultSet rs = null;
      PreparedStatement pstmt = null;

      String result = "";

       try 
           {
              //connect to DB 
              currentCon = ConnectionManager.getConnection();
              pstmt = currentCon.prepareStatement("select * from course_info where course_code=? and c_date=? and start_time=? and end_time=? and venue=?", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
              pstmt.setString(1, CoursesID);
              pstmt.setString(2, strDate);
              pstmt.setString(3, strTime);
              pstmt.setString(4, endTime);
              pstmt.setString(5, venue);
              pstmt.executeQuery();
              rs = pstmt.getResultSet();

              //check whether the class is existed
              if (rs.next()) 
              {

                  rs.updateObject("c_date", courseInfo.getChangeC_date());
                  rs.updateObject("start_time", courseInfo.getChangeStart_time());
                  rs.updateObject("end_time", courseInfo.getChangeEnd_time());
                  rs.updateObject("venue", courseInfo.getChangeVenue());
                  rs.updateRow();
                  result = "Lecture slot updated successfully!";
              }else{
                  result = "You do not have lecture with the details provided in 'current lecture slot' fields. Please check your schedule.";

              }
            } 
        //catch
        //some exception handling

       return result;

   }

错误消息:

 [MySQL][ODBC 5.3(a) Driver]
[mysqld-5.5.43-0ubuntu0.14.04.1]
Table 'sql679933.COURSE_INFO' doesn't exist

每当我提供正确的数据集时,表course_info中的数据都会更新。但是,如果提供了错误的数据集,程序将停在第pstmt.executeQuery();行。

EG。

正确的数据:select * from course_info where course_code='SSK3100'.....(工作正常)

数据不正确:select * from course_info where course_code='SSK333'......(无法执行查询)

此查询在本地数据库中工作正常,所以这里出了什么问题? :(请帮忙。

0 个答案:

没有答案