public List<Affair> queryByTime(String year,String month,String date){
List <Affair> list=new ArrayList<Affair>();
Affair affair;
try{
con=TestDataBase.getConnection();
stmt=con.createStatement();
if(year!=null&&month!=null&&date!=null){
String str="select * from affair where left(time,4)="+year+"and mid(time,6,2)="+month+"and mid(time,9,2)="+date;
rs=stmt.executeQuery(str);
System.out.println(str);
}
else if(year!=null&&month!=null&&date==null){
String str="select * from affair where left(time,4)="+year+"and mid(time,6,2)="+month;
rs=stmt.executeQuery(str);
System.out.println(str);
}
上面是代码 if else if 中 当满足第一个if的值时第一个if里的内容会执行 但是如果满足的是else if时 else if里面的内容却不能执行 服务器还报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
求各位大神帮忙看看
List <Affair> list=new ArrayList<Affair>();
Affair affair;
try{
con=TestDataBase.getConnection();
stmt=con.createStatement();
if(year!=null&&month!=null&&date!=null){
String str="select * from affair where left(time,4)="+year+"and mid(time,6,2)="+month+"and mid(time,9,2)="+date;
rs=stmt.executeQuery(str);
System.out.println(str);
}
else if(year!=null&&month!=null&&date==null){
String str="select * from affair where left(time,4)="+year+"and mid(time,6,2)="+month;
rs=stmt.executeQuery(str);
System.out.println(str);
}
上面是代码 if else if 中 当满足第一个if的值时第一个if里的内容会执行 但是如果满足的是else if时 else if里面的内容却不能执行 服务器还报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
求各位大神帮忙看看
;