0

MYSQLからコピーしたSQLクエリがあり、引用符を削除しましたが、機能しないようです。

 conn = connect();
           selectStatement = "UPDATE student SET Item ? = ?, Type ? = ? WHERE ID = ?";
           System.out.println(selectStatement);
           if(conn != null)
           {
                preparedStatement = conn.prepareStatement(selectStatement);       
                preparedStatement.setString(2, id);
                preparedStatement.setInt(1, location);
                preparedStatement.setInt(3, location);
                preparedStatement.setString(4, type);
                preparedStatement.setString(5, userId);
                preparedStatement.executeUpdate();        
                return true;

スローされた例外がこれであるため、なぜそれが機能しないのかわかりません

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL構文にエラーがあります。MySQLサーバーのバージョンに対応するマニュアルで、「1=」の近くで使用する正しい構文を確認してください。1行目で「1=」「asd」「WHEREID=」「student1」と入力してください。

4

1 に答える 1

1

結局、これはうまくいきました。

          conn = connect();
          selectStatement = "UPDATE student SET `Item " + location + "` = ? , `Type " + location + "` = ? WHERE ID = ?";
          System.out.println(selectStatement);
          if(conn != null)
          {
               preparedStatement = conn.prepareStatement(selectStatement);       
               preparedStatement.setString(1, id);
               preparedStatement.setString(2, type);
               preparedStatement.setString(3, userId);
               preparedStatement.executeUpdate();        
               return true;
          }
于 2013-03-27T04:58:38.600 に答える