0
Why does the following database entry code not work? The code reaches Joption "arrived!"
private void btnCadastroActionPerformed(java.awt.event.ActionEvent evt) {
String sql = "INSERT INTO tbl_cliente(id, nome, nascimento, cpf, sexo, endereco, numero, bairro, cidade,estado, data_entrada, preco_pagamento, datapagamento, mespago)VALUES (12, "+txtNome.getText()+", 1222-10-20, 12312, 123, 123, 123, 123, 123,23, 123, 123, 123, 123)";
JOptionPane.showMessageDialog(null, "chegou?", "chegou?", JOptionPane.INFORMATION_MESSAGE);
try {
pst = conecta.prepareStatement(sql);;
pst.executeQuery(sql);
JOptionPane.showMessageDialog(null, "Cadastrado", "Cadastrado", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException error) {
}
}
Do you have an error? You must be returning an error, but you have a catch that does not serve any purpose in the code. Add the following line inside the
catch
:error.printStackTrace();
– user28595
@diegofm disagree, serve yes, serve to hide the error and hinder the solution :)
– Maniero
no error, you click and it appears the first warning, but does not insert
– Diego Noceli
gave this error org.postgresql.util.Psqlexception: You cannot use query methods that take a query from a prepared command.
– Diego Noceli
I’m new here kk sorry!
– Diego Noceli
The error is giving you the problem, the method
executeQuery
is for consultations ofselect
, Insert should use theexecuteUpdate
– user28595
I’ve tried and you still have the same mistake..."you can’t use the methods"
– Diego Noceli