我试图从数据库中获取数据,其中date = jdatechooser: [英] I am trying to fetch data from database where date = jdatechooser:
问题描述
我有一个带有日期时间列的表我想从数据库中检索数据,其中jdatechooser中指定了日期,但是他们不断收到错误:
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:
无法对
的非静态方法getDate()进行静态引用JDateChooser类型
Cannot make a static reference to the non-static method getDate() from the type JDateChooser
这是代码:
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();
}
}
推荐答案
理论上可以在窗口上安装许多不同的 JDateChooser
控件。所以当你引用其中一个时,你需要指定哪一个,而不是只是调用它 JDateChooser
。
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;
你声明一个变量来引用你的 JDateChooser
- 也就是说,你给它一个名字。现在,当你在 actionPerformed $ c $中引用你的
JDateChooser
时,你需要使用 EXACT SAME NAME c>方法。例如
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();
但不要写 theChooser
- 写当您声明变量时,您给出 JDateChooser
的名称。
But don't write theChooser
- write whatever name YOU gave the JDateChooser
when you declared the variable.
这篇关于我试图从数据库中获取数据,其中date = jdatechooser:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!