gpt4 book ai didi

java - 使用 jcalender 时,我无法通过 MySQL 从 java 应用程序中按日期搜索?

转载 作者:行者123 更新时间:2023-12-01 16:49:34 25 4
gpt4 key购买 nike

try {
JasperDesign jd=JRXmlLoader.load("C:\\Users\\Netcom\\Documents\\NetBeansProjects\\Hamody\\ReportD.jrxml"); // Full address of you Report in between the “”
// String sql = " SELECT * FROM `movie` WHERE acc_num =" + search.getText().toString()+" "; // للبحث عن نص او رقم
// String sql = " SELECT * FROM `movie` WHERE acc_num =" +jComboBox1.getSelectedItem() .toString()+" "; // للبحث عن نص او رقم

String sql = " SELECT * FROM `movie` WHERE `date` = "+jDateChooser3.getDate()+" ";
JRDesignQuery newQuery=new JRDesignQuery();
newQuery.setText(sql);
jd.setQuery(newQuery);

JasperReport jasperReport = JasperCompileManager.compileReport(jd);
JasperPrint jasperprint = JasperFillManager.fillReport(jasperReport, null,con);
JRViewer v = new JRViewer (jasperprint);
jPanel2.setLayout(new BorderLayout());
jPanel2.add(v);

} catch (JRException ex) {
Logger.getLogger(Reportd.class.getName()).log(Level.SEVERE, null, ex);

}


}

最佳答案

Mysql 使用“YYYY-MM-DD”格式存储日期。因此,您需要使用格式化程序来格式化从 jDateChooser3.getDate()

获取的日期

替换下面的行

String sql = "SELECT * FROM movie WHERE date = "+jDateChooser3.getDate()+"";

String sql = "SELECT * FROM movie WHERE date = "+new SimpleDateFormatter("YYYY-MM-DD").format(jDateChooser3.getDate ())+"";

关于java - 使用 jcalender 时,我无法通过 MySQL 从 java 应用程序中按日期搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61719493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com