Java搜索数据库到表

时间:2018-04-19 16:22:07

标签: java database search database-connection

我无法在数据库中搜索记录,当我写文件到TextField TableModel正在加载但不在数据库中搜索时,表格是明确的。

private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {                                        

    jTabbedPane1.setSelectedIndex(2);
     try {

        File currDir= new File ("Baza.db");
        String sc = currDir.getAbsolutePath();
         sc = sc.substring(0, sc.length());

         String url = "jdbc:sqlite://"+sc;
         Connection conn = DriverManager.getConnection(url);
         String wyszukaj =" SELECT * FROM WydatkiStale WHERE id_WydatekStaly =?";
         PreparedStatement pst  = conn.prepareStatement(wyszukaj);
         pst.setString(1,"value");
         ResultSet rs = pst.executeQuery();


   jTable3.setModel(DbUtils.resultSetToTableModel(rs));

    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e);
    } 
}

application window view

1 个答案:

答案 0 :(得分:0)

问题很可能在这里:

java.awt.event.KeyEvent evt

您在每个数据库查询中使用硬编码值,但您应该使用TextField=IF(ISBLANK(G2),"",TODAY()-G2)内容中的动态获取值