各位好,在JSP页面中,有个表格,显示是今年的出入库记录,但是我想每次只显示本月的记录(系统自动判断当前是几月),我想到先取得本月的数值,然后用数据库查询显示出来。我想要的结果是:现在是2010年7月,本月记录如下:
   时间                   货物                     接收人
2010-07-06               显示器                     123
而我现在的情况是把所有的记录都显示了,如下所示   时间                   货物                     接收人
2010-05-06                鼠标                     123
2010-06-06                键盘                     123   
2010-07-06               显示器                     123
由于我是菜鸟,所以不指点具体实现方法,各位高手帮帮忙啊~~~
问题补充:对了,我用的是sql2000数据库。应该怎么实现呢?我现在只知道用date.getMonth()来提取“月份”,然后我就可以用select语句,请问具体代码怎么写?麻烦说详细一点啊,我是菜鸟~~~。
再次感谢各位~~~~

解决方案 »

  1.   


    public static void main(String[] args) {
    Calendar c = Calendar.getInstance();
    String strdate=DateToString(c.getTime());
    String[] array=strdate.split("-");
    Date date=StringToDate(array[0]+"-"+array[1]+"-"+"01");
            c.setTime(date);
            c.add(Calendar.MONTH,-1);
            Date oldDate=c.getTime();
            c.add(Calendar.MONTH,2);
            Date newDate=c.getTime();
            //我们程序中获得了上个月oldDate 下个月newDate
            String sql="select * from table as t where t.date between oldDate and newDate";
            //下面是你执行语句检索
    } public static Date StringToDate(String dateStr) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Date date = null;
    try {
    date = format.parse(dateStr);
    } catch (ParseException e) {
    e.printStackTrace();
    }
    return date;
    }
    public static String DateToString(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    String dateStr = format.format(date);
    return dateStr;
    }