Why does not my java project allow me to insert data into mysql, although I do not see any errors?

0
  private void GuardarActionPerformed(java.awt.event.ActionEvent evt) {                                        

     try {
    conexion c =new conexion();

    Statement s= c.con.createStatement();
    ResultSet rs=s.executeQuery("SELECT * from cliente");
    s.executeUpdate("INSERT INTO cliente (Cod_Cliente, Nombre_Cliente,Numero_Mesa)Values(´"+CodigoCliente.getText()+"´,´"+NombreCliente.getText()+"´,´"+Mesa.getText()+"´)");
     }catch(ClassNotFoundException | SQLException e)
     {
     System.out.print("Error"+e);
     }
    }                                       
    
asked by Gloria Ximena 22.11.2018 в 00:11
source

1 answer

0

I would make the following change:

try {
    conexion c =new conexion();

    Statement s= c.con.createStatement();
    // ResultSet rs=s.executeQuery("SELECT * from cliente");
    s.executeUpdate("INSERT INTO cliente (Cod_Cliente, Nombre_Cliente,Numero_Mesa)Values('"+CodigoCliente.getText()+"','"+NombreCliente.getText()+"','"+Mesa.getText()+"')");
}catch(ClassNotFoundException | SQLException e){
    System.out.print("Error"+e);
}

I advise you to place the classes with Capital letters by standard. That is, the connection class should be called Connection. I also changed the 'for'. Greetings!

    
answered by 22.11.2018 в 17:01