'query' accumulates queries, and one is INSERT INTO root:
public StringBuffer query = new StringBuffer("");
private String tmp="";
tmp="INSERT INTO `root` (`root_`) VALUES ('";
tmp=tmp.concat(root);
tmp=tmp.concat("');");
query.append(tmp);
PreparedStatement ps = con.prepareStatement(query.toString());
ps.executeUpdate();
query.delete(0, query.length());
The first time I did this was normally compiled.
System.out.println(query); show this:
INSERT INTO `root` (`root_`) VALUES ('value1');
But the second time 'query' contains:
INSERT INTO `rel_root_doc` (`freq`,`id_doc`, `id_root`) VALUES (1,1,1);
INSERT INTO `root` (`root_`) VALUES ('value2');
and I'm having this 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 .
'INSERT INTO `root` (`root_`) VALUES ('value2')' at line 2
But if I copy and paste the same code in MySQLWorkbench, it works perfect.
Thanks for read.
?parameter placeholder.