I have an sql table sysuser looking like this:
id (pk) email password role
I’d like to insert values into the table. I get the data in ArrayList<String>:
cell 0 no value,
cell 1 ID,
cell 2 email,
cell 3 password,
cell 4 role,
Here is the code i’ve written:
stmt.executeUpdate("INSERT INTO sysuser VALUES ('"+string.get(1)+"', '"+ string.get(2) +"','"+ string.get(3) +"','"+string.get(4)+"'");
where string is the ArrayList<String>.
The code is not working and I can’t figure why. It works perfectly with another query. I get 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 ” at line 1
I read about prepared statments but I did not understand the syntax. I know that it is not safe to insert data directly, yet for this specific query it doesn’t matter.
You forgot a
)And if you are not filling all columns of your table you should provide a list of columns you are inserting into like this