java怎么查询数据库一周内的记录
tab1.setNumRows(0);Calendarca=Calendar.getInstance();//获取Calendar实例Datedate2=newDate(...
tab1.setNumRows(0);
Calendar ca= Calendar.getInstance();//获取Calendar实例
Date date2 = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String s_date = dateFormat.format(date2);
try {
ca.setTime(DateFormat.getDateInstance().parse(s_date));
b=ca.get(ca.DAY_OF_YEAR);
} catch (ParseException e1) {
e1.printStackTrace();
}
int month[] = null;
String[] monthdate=null;
for(int s=0;s<=num;s++){
try {
ca.setTime(DateFormat.getDateInstance().parse(String(a[s][2])));
month[s]=ca.get(ca.DAY_OF_YEAR);
System.out.println(month[s]);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
for(int s=0;s<=num;s++){
if(b-month[s]<=30){
monthdate[s]=(java.lang.String) a[s][2];
}
}
我想从数据库取出日期与当天相减,然后重新查询刷新TABEL
却出现错误
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1380)
at java.text.DateFormat.parse(DateFormat.java:355)
at load.Business$3.actionPerformed(Business.java:216) 展开
Calendar ca= Calendar.getInstance();//获取Calendar实例
Date date2 = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String s_date = dateFormat.format(date2);
try {
ca.setTime(DateFormat.getDateInstance().parse(s_date));
b=ca.get(ca.DAY_OF_YEAR);
} catch (ParseException e1) {
e1.printStackTrace();
}
int month[] = null;
String[] monthdate=null;
for(int s=0;s<=num;s++){
try {
ca.setTime(DateFormat.getDateInstance().parse(String(a[s][2])));
month[s]=ca.get(ca.DAY_OF_YEAR);
System.out.println(month[s]);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
for(int s=0;s<=num;s++){
if(b-month[s]<=30){
monthdate[s]=(java.lang.String) a[s][2];
}
}
我想从数据库取出日期与当天相减,然后重新查询刷新TABEL
却出现错误
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1380)
at java.text.DateFormat.parse(DateFormat.java:355)
at load.Business$3.actionPerformed(Business.java:216) 展开
2个回答
展开全部
空指针异常,大体看了一下,month[s]=ca.get(ca.DAY_OF_YEAR)貌似不对,数组越界了。今天(2013/12/22),ca.get(ca.DAY_OF_YEAR)=356,虽然没看明白你想干什么,但是从你起的名来看应该是Calendar.DAY_OF_MONTH
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询