当我在没有where条件的情况下编写sql代码时,我得到了结果。我认为准备好的声明没有从JDateChooser
访问日期。
private void datesearchActionPerformed(java.awt.event.ActionEvent evt) {
try {
JDBCCategoryDataset dataset = new JDBCCategoryDataset("jdbc:mysql://localhost:10061/goshope","com.mysql.jdbc.Driver","root","tiger");
String qry= "select item,SUM(quantity) from bill_electronics where date=? GROUP BY item";
ps= con.prepareStatement(qry);
// String qry= "select item, SUM(quantity) from bill_electronics GROUP BY (item)";
SimpleDateFormat sdf=new SimpleDateFormat(" dd,MM,YYYY");
String date =datechart.getDateFormatString();
ps.setDate(1,new java.sql.Date(datechart.getDate().getTime()));
dataset.executeQuery(qry);
JFreeChart chart = ChartFactory.createBarChart("Daily Report","item", "qty", dataset, PlotOrientation.VERTICAL,false, true, true);
BarRenderer renderer = new BarRenderer();
CategoryPlot plot=null;
ChartFrame frame =new ChartFrame("Daily Report", chart);
frame.setVisible(true);
// frame.setSize(400,650);
ChartPanel chartpanel= new ChartPanel(chart);
panel1.removeAll();
panel1.add(chartpanel,BorderLayout.CENTER);
panel1.validate();
} catch (Exception e) {
e.printStackTrace();
}
}
我认为准备好的声明不会从JDateChooser访问日期。如果我提供特定日期或没有'其中'在sql代码上的条件,然后我得到正确的答案。