0

I'm trying to insert into a database with the following columns, however I'm getting the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Id) Values ('Gonzalo','Higuain','09 7 2018','Argentina',12.0,'Attacker','Right',' at line 1

  1. id, int auto-increment

  2. FirstName, Text

  3. LastName, Text

  4. DateOfBirth, Text

  5. Nationality, Text

  6. Height, Float

  7. Position, Text

  8. StrongFoot, Text

  9. TeamId, Int

        DatabaseConnection DatabaseConnect= new DatabaseConnection();     
        DatabaseConnect.getConnection();                                  
        Statement mystatement = DatabaseConnect.myConn.createStatement();
        String club = ("Insert into players ( FirstName, LastName, DateOfBirth, Nationality, Height, Position, StrongFoot, Team Id) Values (?,?,?,?,?,?,?,?)");
        PreparedStatement input = DatabaseConnect.myConn.prepareStatement(club);
        input.setString(1, fName);
        input.setString(2, lName);
        input.setString(3, formattedDate);
        input.setString(4, nationality);
        input.setDouble(5, height);
        input.setString(6, position);
        input.setString(7, foot);
        input.setInt(8, teamId);
        input.executeUpdate();
    
1
  • You never used mystatement? Commented Jul 6, 2018 at 2:48

1 Answer 1

4
String club = ("Insert into players ( FirstName, LastName, DateOfBirth, Nationality, Height, Position, StrongFoot, Team Id) Values (?,?,?,?,?,?,?,?)");

I think Team Id above should be TeamId. You have a space in there. Here's what it should be:

String club = ("Insert into players ( FirstName, LastName, DateOfBirth, Nationality, Height, Position, StrongFoot, TeamId) Values (?,?,?,?,?,?,?,?)");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.