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
id, int auto-increment
FirstName, Text
LastName, Text
DateOfBirth, Text
Nationality, Text
Height, Float
Position, Text
StrongFoot, Text
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();
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 (?,?,?,?,?,?,?,?)");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.