if(type.compareTo("fire") == 0)其中type是String型,在什么情况下会报错啊?
具体错误如下:org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 7370: int second = calendar.get(GregorianCalendar.SECOND);
71: String date = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
72: //String str1 = "fire";
73: if(type.compareTo("fire") == 0){
改成 "fire".compareTo(type) == 0 应该就可以了
原因是可能由于其他地方的语法等问题,导致type没有被赋值
这个没有问题啊type的值是什么?
String query="INSERT INTO Tommorrow VALUES('";
GregorianCalendar calendar = new GregorianCalendar();
int year = calendar.get(GregorianCalendar.YEAR);
int month = calendar.get(GregorianCalendar.MONTH);
int day = calendar.get(GregorianCalendar.DAY_OF_MONTH);
int hour = calendar.get(GregorianCalendar.HOUR_OF_DAY);
int minute = calendar.get(GregorianCalendar.MINUTE);
int second = calendar.get(GregorianCalendar.SECOND);
String date = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
//String str1 = "fire";
if(("fire").compareTo(type) == 0){
query+=date;query+="','";query+=thing;query+="',1,2)";
statement.executeUpdate(query);
}
if(type/*.compareToIgnoreCase("happy")*/ == /*0*/"happy"){
query+=date;query+="','";query+=thing;query+="',2,2)";
statement.executeUpdate(query);
}
if(type/*.compareToIgnoreCase("workless")*/ == /*0*/"workless"){
query+=date;query+="','";query+=thing;query+="',3,2)";
statement.executeUpdate(query);
}
if(type/*.compareToIgnoreCase("game")*/ == /*0*/"game"){
query+=date;query+="','";query+=thing;query+="',4,2)";
statement.executeUpdate(query);
}
}
改为
if("fire".equals(type))
要不判断null 要不 用5楼的 equals 并且 type必须放后