Java dbc搜索按钮代码问题

时间:2017-06-22 06:38:11

标签: search jdbc prepared-statement

我有这段代码片段,在编译时没有错误或问题。但是当我运行代码搜索按钮时不搜索。我的问题是什么?

 JButton btnSearch = new JButton("Search");
    btnSearch.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0){
            try {
                String query ="select * from InternTable where  InternName like ? OR BirthDate like ? OR"
                        + " Comments like ? OR Adress like ? OR InternGSM like ? OR EMail like ? OR "
                        + "School like ? OR Project like ? OR Department like ?"
                        + "OR Competence1 like ? OR Competence2 like ? OR Competence3 like ? OR"
                        + "Competence4 like ? OR Competence5 like ?"; 

                PreparedStatement pst = connection.prepareStatement(query);
                pst.setString(1, "%"+tvInternTable.getText()+"%");
                pst.setString(2, "%"+tvInternTable.getText()+"%");
                pst.setString(3, "%"+tvInternTable.getText()+"%");
                pst.setString(4, "%"+tvInternTable.getText()+"%");
                pst.setString(5, "%"+tvInternTable.getText()+"%");
                pst.setString(6, "%"+tvInternTable.getText()+"%");
                pst.setString(7, "%"+tvInternTable.getText()+"%");
                pst.setString(8, "%"+tvInternTable.getText()+"%");
                pst.setString(9, "%"+tvInternTable.getText()+"%");
                pst.setString(10, "%"+tvInternTable.getText()+"%");
                pst.setString(11, "%"+tvInternTable.getText()+"%");
                pst.setString(12, "%"+tvInternTable.getText()+"%");
                pst.setString(13, "%"+tvInternTable.getText()+"%");
                pst.setString(14, "%"+tvInternTable.getText()+"%");

                ResultSet rs = pst.executeQuery();
                table.setModel(DbUtils.resultSetToTableModel(rs));
                pst.close();
                rs.close();

            }
            catch (Exception e) {

        } } }
);
    btnSearch.setBounds(115, 43, 89, 23);
    contentPane.add(btnSearch);

0 个答案:

没有答案