如果必须检索干 the的记录,这一记录应当尽可能靠近我的时间段(YYY-MM),请记住,db(sql服务器)的栏目是DATETIME,因此,我需要加以编排,以便比较一下,这里是我一直在做的:
public Document findByDate(String date) throws GeneralException{
Document docs = new Document();
String d1 = date;
String delimiter = "-";
String[]temp = d1.split(delimiter);
try{
String sql = "SELECT TOP(1) * FROM Document WHERE issueDate >= " + temp[1]+ temp[0] +" AND issuedate < "+ temp[1]+ temp[0] +" ORDER BY issueDate DESC ";
ResultSet rs = this.executeQuery(sql);
while(rs.next()){
docs = (Document) this.build(rs);
}
if(docs != null){
return docs;
} else {
return docs = null;
}
} catch (SQLException ex){
throw new GeneralException(ex);
}
}
非常感谢