I am trying to fetch data from database where date = jdatechooser:

馋奶兔 提交于 2019-12-02 11:39:35

问题


I have a table with a column datetime i want to retrieve data from database where date is specified in jdatechooser but em continously getting error:

Cannot make a static reference to the non-static method getDate() from the type JDateChooser

Here is the code:

public void actionPerformed(ActionEvent e) {

                Date date = JDateChooser.getDate();
                try{ 
                String query = " Select *from Transactions WHERE "+date+"=?  ";
                PreparedStatement pst = con.prepareStatement(query);
                ResultSet rs = pst.executeQuery();
                table.setModel(DbUtils.resultSetToTableModel(rs));
                }catch (Exception e1){
                    e1.printStackTrace();
                }

            }

回答1:


It's theoretically possible to have a window with lots of different JDateChooser controls on it. So when you refer to one of them, you need to specify which one, rather than just calling it JDateChooser.

Somewhere in your class, you'll have a declaration something like

private JDateChooser theChooser;

where you declare a variable to refer to your JDateChooser - that is, you give it a name. Now, you need to use the EXACT SAME NAME when you refer to your JDateChooser in your actionPerformed method. For example

Date date = theChooser.getDate();  

But don't write theChooser - write whatever name YOU gave the JDateChooser when you declared the variable.



来源:https://stackoverflow.com/questions/46292039/i-am-trying-to-fetch-data-from-database-where-date-jdatechooser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!