SQLException: Invalid handle 是怎么回事?
以下的程序是从database里select某些数据
其中我用个一个class(DateParser1) 来实行从String到java.sql.Date的 转化
public class DateParser1{
java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("dd/MM/yyyy");
java.text.SimpleDateFormat sdf2 = new java.text.SimpleDateFormat("HH:MM:SS");
public String stringToDate(String str){
try{
return sdf1.format(sdf1.parse(str));
}catch(Exception e){
e.printStackTrace();
return null;
}
}
public String stringToTime(String str){
try{
return sdf2.format(sdf2.parse(str));
}catch(Exception e){
e.printStackTrace();
return null;
}
}
然后在执行的时候就报错,我不确定时间是不是要用'',但是用不用都报一样的错,到底是哪里的问题啊
try{
cs2="select TimeInsert, Value from HISTORY_INFO where DateInsert = " +dp.stringToDate(date)+
" and Logical_Address='S7' and TimeInsert between '" +dp.stringToTime(timeto) +
"' and '" +dp.stringToTime(timefrom)+"'";
rs2= stmt.executeQuery(cs2);
System.out.println(cs2);
while(rs2.next()) {
String time=rs2.getDate("TimeInsert").toString();
String value = rs2.getString("Logical_Address");
for(t=0;;t++){
result[t][0]=time;
result[t][1]=value;
}
}
stmt.close();
con.close();
}catch(SQLException ex) {
System.err.println("SQLException: "+ex.getMessage()+cs2);
}