我在我的 sql 查询中遇到错误,我需要更改哪些内容来改进我的编码
我的代码是
我的 DBHelper 代码
public Cursor fetchDaysAppointment(String from, String to){
Cursor c = ourDatabase.rawQuery("SELECT * FROM "+CUSTOMER_TABLE_NAME+
"WHERE (aDate >= ? AND aDate <= ?)",
new String[]{from, to});
if(c != null){
c.moveToFirst();
}
return c;
}
我的 Java 代码
public void getDaysAppointment(int day, int month, int year){
String from = year+"-"+month+"-"+day+" 00:00:00";
String to = year+"-"+month+"-"+day+" 23:59:59";
in.open();
cursor = in.fetchDaysAppointment(from, to);
cursor.moveToFirst();
for(int i=0; i<cursor.getCount(); i++){
if(cursor.getInt(cursor.getColumnIndex("aTime")) == 8){
System.out.println("Hi the value is found to be Matched");
}
cursor.moveToNext();
}
}
日志猫错误
02-14 17:23:06.740: E/AndroidRuntime(4535): FATAL EXCEPTION: main
02-14 17:23:06.740: E/AndroidRuntime(4535): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ashadegreen/com.example.ashadegreen.Home}: android.database.sqlite.SQLiteException: near "(": syntax error: , while compiling: SELECT * FROM customerWHERE (aDate >= ? AND aDate <= ?)