java - Eclipse SQLite 使用Where 子句进行多个查询

标签 java mysql eclipse swing sqlite

您好,我正在尝试使用 Jtextfield 框通过我创建的 Jtable 来搜索 sqlite 数据库中的值。到目前为止我有代码:

    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();
            }


        }
    });

这段代码只允许我搜索1列数据,而我想搜索整个数据库。我尝试过在 where 和其他替代方案之后使用“OR”语句,但没有任何效果。任何建议或修复将不胜感激!

最佳答案

您应该能够使用 OR。对于每个项目,您将需要应用另一“组”。

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

我无权发表评论;这是我唯一的回应选择。

关于java - Eclipse SQLite 使用Where 子句进行多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31527300/

相关文章:

android - 如何在 Eclipse Indigo 中禁用 m2e 构建?

eclipse - 如何在eclipse中配置less?

java - 如何在HQL中转义关键字 "on"

php - 更新数据库后重定向的代码

mysql - node.js mysql错误: ECONNREFUSED

php - 对于 Web 应用程序,将多个页面上的嵌套讨论分开的最佳方法是什么?

java - 我可以使 eclipse SWT UI 看起来像 Eclipse 插件 UI 吗?

Java:安全地强制转换 ArrayList 的克隆?

java - 使用我自己的字典创建 CMUSphinx 语言模型后的下一步是什么?

java - 通过对数组进行排序来创建排名列表