Use quotes around your dates:
rs = stmt.executeQuery("SELECT sales.InvoiceNumber, sales.ShipToAddress, sales.Date "
+ "FROM sales, customers "
+ "WHERE sales.CardRecordID = customers.CardRecordID "
+ "AND customers.Name = 'Cash Sales' "
+ "AND sales.Date BETWEEN '" + sdate + "' AND '" + edate + "' "
+ "ORDER BY sales.ShipToAddress ASC, sales.Date DESC"
+ ";");
Or it might be safer to use a prepared statement (if the dates come from untrusted inputs for example):
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
java.util.Date startDate = formatter.parse(sdate);
java.util.Date endDate = formatter.parse(edate);
PreparedStatement pstmt = connection.prepareStatement("SELECT sales.InvoiceNumber, sales.ShipToAddress, sales.Date "
+ "FROM sales, customers "
+ "WHERE sales.CardRecordID = customers.CardRecordID "
+ "AND customers.Name = 'Cash Sales' "
+ "AND sales.Date BETWEEN ? AND ? "
+ "ORDER BY sales.ShipToAddress ASC, sales.Date DESC");
pstmt.setDate(1, new java.sql.Date(startDate.getTime()))
pstmt.setDate(2, new java.sql.Date(endDate.getTime()))
The between operator is inclusive, but if your database field is actually a timestamp, then a date with no time is assumed to be at time 00:00:00.000. So, in such a case, for your dates to be inclusive, you can add one day to your end date. Technically it will also include the first instant of the next day (00:00:00.000 hour), but depending on your application it may be enough.
Otherwise you could use >=
on "start date" and <
on "end date plus one day":
"sales.Date >= '" + sdate + "' AND sales.Date < '" + edatePlusOne + "' "
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…