I'm trying to make an app from a veterinary clinic and I followed all the right steps to create the database, connect with the eclipse, and so on. The program connects but does not enter anything that was entered into the program in the database, although the message shows that the registration was successful.
package BD;
import java.sql.*;
import java.sql.*;
public class BancoDeDados {
private static String url = "jdbc:mysql://localhost:3306/bd?autoReconnect=true&useSSL=false";
private static String user = "root";
private static String pass = "artpop";
protected static Connection conexao = null;
public BancoDeDados(){
if(conexao==null) conecta();
}
public static boolean conecta(){
try {
conexao = DriverManager.getConnection(url,user,pass);
return true;
}catch(SQLException e){
System.out.println(e.getMessage());
return false;
}
}
public static boolean desconecta(){
try{
conexao.close();
return true;
}catch(SQLException e){
return false;
}
}
}
DAO ******************************************************************* *** /
package BD;
import java.sql.*;
import javax.swing.JOptionPane;
import java.sql.Statement;
import java.util.ArrayList;
public class ClienteDao extends BancoDeDados{
public boolean adicionarCliente(Cliente c){
try{
Statement st = conexao.createStatement();
st.executeUpdate("insert into clientes values ('" + c.getNome_cliente()+"','"+c.getCpf_cliente()+"','"+c.getrg_cliente()+"','"+c.gettelefone_cliente()+"','"+c.getEndereco_cliente()+"');");
return true;
}catch(SQLException e){
return false;
}
}
For screen:
continuar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ClienteDao clienteDAO = new ClienteDao();
try{
Cliente cliente = new Cliente(nome.getText(), cpf.getText(), rg.getText(), telefone.getText(), endereco.getText());
clienteDAO.adicionarCliente(cliente);
JOptionPane.showMessageDialog(null, nome.getText() + "Cadastro realizado com sucesso!!");
}catch(Exception er){
JOptionPane.showMessageDialog(null,"Não foi possível realizar cadastro, verifique!");
}
}
});