我有一个包含“日期”列的表格,并以格式输入日期:“2011-09-06”,我想执行查询:
select * from tvprograms where date=?
我试试这个:
Date startDate;
java.util.Date date;
Calendar cal = Calendar.getInstance();
cal.set(2011, 9, 1);
startDate = cal.getTime();
TVProgramDAO tvDAO = new TVProgramDAO();
tvDAO.findUnusedTvPrograms(new java.sql.Date(date.getTime()));
findUnusedTvPrograms 看起来:
public List<Integer> findUnusedTvPrograms(Date date) {
List<Integer> results = new ArrayList<Integer>();
if (obtainConnection()) {
PreparedStatement stmt = null;
ResultSet rs = null;
...
stmt = con.prepareStatement(findOldTvProgQuery.toString());
stmt.setDate(1, date);
rs = stmt.executeQuery();
while (rs.next()) {
results.add(rs.getInt(1));
...
return results;
}
但它不起作用。