为什么日期格式没有正确填充?

时间:2015-06-27 06:12:05

标签: java swing odbc

我已从数据库中填充了JTable。所有数据都已正确填充。但 DateofSupply 看起来不正确。任何人都可以告诉我我在做什么错吗?提前致谢。 enter image description here

这是我填充Jtable的源代码。

Date date1 = dateChooser_3.getDate();
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy");
fromdate = formatter.format(date1);
Date date2 = dateChooser_4.getDate();
todate = formatter.format(date2);
supplier = ((String)comboBox.getSelectedItem());

System.out.println(fromdate+"\t"+todate+"\t"+supplier);

double[] total = new double[100];
Date[] date = new Date[100];
int i = 0;
try
{
    String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=c:\\db.accdb";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection(url);

    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery("select id,Rate,MilkSupplied,DateofSupply FROM records WHERE (((DateofSupply) Between #"+fromdate+"# And #"+todate+"#)) AND CustName='"+supplier+"'");

    while (rs.next())
    {
         total[i] = (rs.getDouble("MilkSupplied") *rs.getDouble("Rate"));
         date[i] = rs.getDate("DateofSupply");
         System.out.println(total[i]+"\n"+date[i]+"\n"+i);
         i++;
    }

    int j = 0;
    while (j < i)
    {
         System.out.println("\n"+total[j]+"\n"+date[j]+"\n"+j);
         st.executeUpdate("Update records SET Total='"+total[j]+"'WHERE DateofSupply=#"+date[j]+"# ");
         j++;
    }
    con.commit();                          

    String sql1 ="SELECT CustName,MilkSupplied,DateofSupply,FAT,TimeofSubmit,Rate,Total FROM records WHERE (((DateofSupply) Between #"+fromdate+"# And #"+todate+"#)) AND CustName='"+supplier+"'";
    PreparedStatement pst = con.prepareStatement(sql1);
    ResultSet rs2 = pst.executeQuery();

    table.setModel(DbUtils.resultSetToTableModel(rs2));                        
    dtm =table.getModel();

    String sql2 ="SELECT SUM(Total) FROM records WHERE (((DateofSupply) Between #"+fromdate+"# And #"+todate+"#)) AND CustName='" +supplier+"'";
    PreparedStatement pst2 = con.prepareStatement(sql2);
    ResultSet rs3 = pst2.executeQuery();

    if (rs3.next())
    {
       Double sum = Double.valueOf(Double.parseDouble(rs3.getString(1)));
       System.out.println(sum);
       lblTotal.setText(String.valueOf(sum));
    }

    rs3.close();                          
    pst.close();
    con.close();                         
}
catch (Exception ex)
{
    System.err.print("Exception: ");
    System.err.println(ex.getMessage());
}

0 个答案:

没有答案