mardi 23 août 2016

Filter results displayed in sqlite query using checkboxes in Java

I'm trying to make a query that filters the results based on multiple checkboxes. "SELECT * FROM tblRhino WHERE Gender='M' AND Type='White'" Should be send to sqlite if the checkbox Male and White are selected. Now I have 8 checkboxes. Each rhino has one gender, one type and one feeding pattern.

The checkboxes have been converted into booleans as follows:

    if(chckbxBlack.isSelected())
        cBlack = true;
    else
        cBlack = false;

I have tried to do this; but it doesn't want to work.

    JButton btnSpecificRhinos = new JButton("Specific rhino's");
    btnSpecificRhinos.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) 
        {           
            if(cMale = true)
                if(cFemale = false)
                    if(cWhite = true)
                        if(cBlack = false)
                            if(cFP1 = true)
                                if(cFP2 = false)
                                    if(cFP3 = false)
                                        if(cFP4 = false)
                                        {
                                            try
                                            {
                                                String query = "SELECT * FROM tblRhino WHERE Gender='M' AND Type='White' AND FeedingPattern=1";
                                                PreparedStatement pst = conn.prepareStatement(query);
                                                ResultSet rs = pst.executeQuery();                      
                                                    tableRhino.setModel(DbUtils.resultSetToTableModel(rs)); 
                                            }
                                            catch(Exception ex)
                                            {
                                                ex.printStackTrace();
                                            }
                                        }
        }
    }




Aucun commentaire:

Enregistrer un commentaire