Save data from a JCheckBox in SQL Server?

0

I have the following JCheckBox:

and I need to collect the data of each of them to insert in the table with a "yes" if they select it, and "null" if they did not select it, someone has an idea how can I do that ????

Here I leave the code I use to save the rest that are jtextfield

JButton btnIngresar = new JButton("Ingresar");
btnIngresar.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        try {
            Connection conexion = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=Prueba2ºIF;user=sa;password=123456789;");

            if (MisMetodos.buscarCi(ci.getText())) {
                JOptionPane.showMessageDialog(null, "El empleado a ingresar ya existe");
            } else {
                String sentenciaSQL = "INSERT INTO [dbo].[Empleado]"+
                                      "([Ci],[Nombre],[Apellido],[Apellido],[Direccion],[Email],[Celular],[Licencia],[Arma],[Fulltime],[MejorArteMarciial],[NumeroServicio])VALUES"
                                      + "("+"'"+ci.getText()+"','"+nombre.getText()+"','"+apellido.getText()+"',"+direccion.getText()+",'"+mail.getText()+"','"+ cel.getText()")";

                Statement statement = conexion.createStatement();
                statement.executeUpdate(sentenciaSQL);
            }

            conexion.close();

            JOptionPane.showMessageDialog(null,"Libro Ingresado");
        } catch (java.sql.SQLException e) {
            System.err.println(e);
        }
    }
});
    
asked by Melannie Nichole 30.10.2017 в 03:30
source

1 answer

0

You could use the isChecked () method that have the checkBox to check if they are marked or not, this would return a boolean, then you do an if to be true,

String infoCheckBox = null;
if(checkBox1.isChecked()){ 
   infoCheckBox = "si";
}

And this variable can be passed to your insert query so that it is reflected in the database that "YES" the checkbox is marked at the time of insertion.

Although I would personally recommend that you simply store a boolean in that variable, and pass that boolean to the database. I hope it helps you.

    
answered by 31.10.2017 в 12:39