1
I’m getting this error message and I can’t find why:
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
the code that returns the error is this:
public void adicionar() {
String sql = "INSERT INTO genius.produtos_comissao_extra (Id_produto, Data_abertura, Valor) VALUES (?,?,?)";
if (!txtValor.getText().equals("")) {
try {
pst = conexao.prepareStatement(sql);
// passando o conteúdo dos calendarios para o "?"
pst.setString(1, lblId.getText());
Date data = new Date(System.currentTimeMillis()); // data atual
String d = data.toString();
pst.setString(2, d);
pst.setString(3, txtValor.getText());
pst.execute(sql);
JOptionPane.showMessageDialog(null, "Comissão extra inserida no produto");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
} else {
JOptionPane.showMessageDialog(null, "Informe o valor");
}
}
The schema of the table is this:
If the 3 fields in your Insert table are not string, you will get an error. You are sure that
Id_produto
andData_abertura
are strings and not, respectively, int and datetime?– user28595
they were yes int and datetime, but even changing the two to scan the continued problem, I tried also using pst.setInt and pst.setDate and the problem continued
– Roberto Gomes
So some field is misnamed, or the path to your table.
– user28595
i tested first on Mysql and worked with the code: INSERT INTO Genius.products_commission_extra (Id_product, Open Data_value) VALUES (2,'2016-09-06',5.3); I couldn’t find the difference
– Roberto Gomes
Add the schema of your table(name, fields and their types) to the question.
– user28595
this ai diegofm
– Roberto Gomes