2017-10-28 5 views
2

準備済みの文を使用して車両テーブルに挿入しようとしています。 This is the table shown in PHPMyAdminJDBC準備文の構文エラー

これは私のJavaコード

try { 
     String sql = "INSERT INTO vehicle (vin, serial, make, model, year, reg.no., status) VALUES (?, ?, ?, ?, ?, ?, ?)"; 
     PreparedStatement statement = con.prepareStatement(sql); 
     statement.setString(1, vin); 
     statement.setString(2, serial); 
     statement.setString(3, make); 
     statement.setString(4, model); 
     statement.setInt(5, 10); 
     statement.setInt(6, 17); 
     statement.setString(7, status); 
     System.out.println(statement.toString()); 

     int rowsInserted = statement.executeUpdate(); 
     if (rowsInserted > 0) { 
      System.out.println("A new user was inserted successfully!"); 
     } 
    } catch (Exception ex) { 
     System.out.println(ex); 
    } 

であり、これは私が無知だ生じる誤差

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' status) VALUES ('dfg', 'dfgfg', 'fg', 'sd564', 10, 17, 'dsf')' at line 1 

です。テーブルのプライマリキーの "id"カラムの値を渡さないと、私と関係がありますか?

答えて

0

reg.no.は有効な列名ではありません。実際に使用する必要がある場合は、それを引用する必要があります。

INSERT INTO vehicle (vin, serial, make, model, year, `reg.no.`, status) 
-- Here ---------------------------------------------^-------^ 
VALUES (?, ?, ?, ?, ?, ?, ?)";