lundi 20 juillet 2015

Eclipse SQLite multiple queries with Where clause

Hi I am trying to use a Jtextfield box to search values in my sqlite database with a Jtable I created. So far I have code:

    textFieldSearchServer = new JTextField();
    textFieldSearchServer.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {

            try {
                String query = "select * from server where sid = ?";
                PreparedStatement pst = connection.prepareStatement(query);
                pst.setString(1, textFieldSearchServer.getText());
                ResultSet rs = pst.executeQuery();


                servertable.setModel(DbUtils.resultSetToTableModel(rs));
                pst.close();


            } catch (Exception f) {
                f.printStackTrace();
            }


        }
    });

This code only allows me to search 1 column of data and I want to search the entire database. I have tried using 'OR' statement after where and other alternatives but nothing is working. Any suggestions or fixes will be deeply appreciated!

Aucun commentaire:

Enregistrer un commentaire