こんにちは、データベースの 1 つのレコードを取得する必要があります。このレコードは、私のパラメーター (日付 (YYYY-MM)) にできるだけ近い必要があります。データベース (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);
}
}
どうもありがとうございました