public List<ChatRecord> getChatRecords(int chatId, String chatCreateTime1,
String chatCreateTime2) {
ArrayList<ChatRecord> chatRecords = new ArrayList<ChatRecord>();
String sql = "select * from chatRecord where chatId = ? and chatCreateTime  between ? and ?";
Connection conn = DBConnection.getConn();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, chatId);
pstmt.setString(2, chatCreateTime1);
pstmt.setString(3, chatCreateTime2);
rs = pstmt.executeQuery();
while (rs.next()) {
ChatRecord chatRecord = new ChatRecord();
chatRecord.setChatId(rs.getInt(1));
chatRecord.setServerName(rs.getString(2));
chatRecord.setChatContent(rs.getString(3));
chatRecord.setChatCreateTime(rs.getDate(4));
chatRecords.add(chatRecord);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBConnection.closeAll(rs, pstmt, conn);
}
return chatRecords;
}public List<ChatRecord> getRecords(int chatId, String chatCreateTime1,
String chatCreateTime2) {
return chatRecordDao.getChatRecords(chatId, chatCreateTime1, chatCreateTime2);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
int chatId = Integer.parseInt(request.getParameter("chatId"));
String time1 = request.getParameter("time1");
String time2 = request.getParameter("time2");
List<ChatRecord> chatRecords = chatRecordBo.getRecords(chatId, time1,
time2);日期是这样的格式2009-03-03这样的 数据库写的也是

解决方案 »

  1.   

    调试一下看下你的参数是否为空。然后看看调试的SQL语句在文本里面复制到SQL环境里面运行一下看看能不是正常的执行。好几个原因呢。这是最基本的。先看看吧
      

  2.   

    那你把你的SQL语句那去单独运行一下,看看有没有结果。
      

  3.   

    你这是java的啊。我看看还好像C#的。呵呵
      

  4.   

    select * from chatRecord where chatId = 888 and chatCreateTime  between '2009-01-01' and '2009-07-07'
    那两个''怎么办?
      

  5.   

    写在字符串里面。string sql=“select * from chatRecord where chatId =’“ ? +”and chatCreateTime  between '+? +"and '"+?+"'"