【发布时间】:2014-05-27 12:44:32
【问题描述】:
我有一个 JComboBox 包含月份(九月,七月...) 和一个 jTable 以及数据库中的一个表 (Bills),其中包含 (Id bill , date , products ..)
我希望当像 september 从 jComboBox 中选择一个值时,它会在 9 月为我提供所有产品。
日期格式如 2014/May/27 14:31:04
我尝试了这段代码,但它没有工作,因为在 java 中我无法使用:
String sql1 = "select Products from Bills where Date LIKE "?????+jComboBox1.getSelectedItem()+*" ";
(它给出一个错误,我无法编译)
代码:
try
{
Class.forName(driver).newInstance();
Connection con = (Connection)DriverManager.getConnection(url,user,pass);
String sql1 = "select Products from Bills where Date LIKE "?????+jComboBox1.getSelectedItem()+* " ";
PreparedStatement pst = con.prepareStatement(sql1);
ResultSet rs = (ResultSet) pst.executeQuery(sql1);
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch( Exception e){
JOptionPane.showMessageDialog(null, e);
}
【问题讨论】:
-
最佳实践,提出查询,并签入数据库,然后继续
标签: java database date jtable jcombobox