java.sql.sqlexception不能为选择发出executeupdate()或执行大型update()

时间:2016-06-09 10:13:36

标签: java mysql exception

  
    

代码给我sqlexception

  
 int rowsAffected=0;
   Connection con=null;
  try{
      String query="select * from payment WHERE Mid = ? AND date = ?";
          con=DataAccessLayer.getConnection();
  int combo=member.getValue().getId();
   Date date =Date.valueOf(datepicker.getValue());
 PreparedStatement stat=con.prepareStatement(query);
   stat.setDate(2, date);
   stat.setInt(1,combo);
      rowsAffected = stat.executeUpdate();
  }
   catch(Exception exx){
          Platform.runLater(()->{
             exx.printStackTrace();

              });
           return;     
        }
  
    

异常堆栈     java.sql.SQLException:无法为SELECTs发出executeUpdate()或executeLargeUpdate()         在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)         在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)         在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)         在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)         在com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2045)         at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)         在com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)         在com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)         在Controllers.MemberbillController.lambda $ choice $ 3(MemberbillController.java:62)         在java.lang.Thread.run(Thread.java:745)

  

1 个答案:

答案 0 :(得分:0)

问题在于您没有正确使用JDBC。为什么要使用select查询调用executeUpdate?

function disableInfo() {

    //first part
    var $disabledInfo = $('#invalidityInfo');
    if($disabledInfo.is(':checked')) {
        $('.disabled-price').show();
    } else {
        $('.disabled-price').hide();
    }

    //second part
    $disabledInfo.unbind('change');
    $disabledInfo.change(function() {
        if($disabledInfo.is(':checked')) {
            $('.disabled-price').show();
        } else {
            $('.disabled-price').hide();
        }
    });
}