Reputation: 958
Do I need to create a new statement each time I execute a query?
This line doesn't work (I have already established connection with the database )
Statement.execute("INSERT INTO PS2 (uuid , team, kills , deaths , rank_lvl, rank_name, pts) "
+ "VALUES"
+ " (`" + name.toString() + "` , `none` , 0 , 0 , 1 , `Starter` , 0)");
I create the table with this code :
Statement.execute("CREATE TABLE IF NOT EXISTS PS2"
+ "(uuid VARCHAR(45),"
+ "team VARCHAR(20),"
+ "kills INTEGER,"
+ "deaths INTEGER,"
+ "rank_lvl INTEGER,"
+ "rank_name VARCHAR(25),"
+ "pts INTEGER)");
After executing the code , the database has been created . Afterwards after trying to insert row, the row is not created!
Upvotes: 0
Views: 79
Reputation: 68790
You're using backticks `
instead of quotes '
to wrap your values. Backticks are only used to wrap column names.
Statement.execute("INSERT INTO PS2 (`uuid` , team, kills , deaths , rank_lvl, rank_name, pts) "
+ "VALUES"
+ " ('" + name.toString() + "' , 'none' , 0 , 0 , 1 , 'Starter' , 0)");
As mention by Caweren, you should be careful of SQL reserved keywords. UUID
could be one of them (with an Oracle V9i database, for example), so you should wrap it with backticks.
Upvotes: 2
Reputation: 244
uuid
is a reserved keyword for SQL, you should wrap it in quotes: `uuid`
Upvotes: 0