Im nouveau en termes de codage, donc je copier coller les codes de certains tutoriels, mais lorsque je suis en train d'essayer de supprimer toutes les données dans la colonne "sleep", cette erreur est affichée.erreur lors de la suppression dans la base de données sqlite
android.database.sqlite.SQLiteException: à proximité de "20170128": erreur de syntaxe (code 1), lors de la compilation: SUPPRESSION DE 20170128 à android.database.sqlite.SQLiteConnection.nativePrepareStatement (natif Method) à android.database.sqlite.SQLiteConnection.acquirePreparedStatement (SQLiteConnection.java:889) à android.database.sqlite.SQLiteConnection.prepare (SQLiteConnection.java:500) à android.database.sqlite.SQLiteSession.prepare (SQLiteSession. java: 588) at android.database.sqlite.SQLiteProgram. (SQLiteProgram.java:58) at android.database.sqlite.SQLiteStatement. (SQLiteStatement.java:31) at android.database.sqlite.SQLiteDatabase.delete (SQLiteDatabase.java:1496) à jm.myapplication.Sleep.sleep_repo.delete1 (sleep_repo.java : 51) à jm.myapplication.Main.MainActivity $ 1.onClick (MainActivity.java:220) à android.view.View.performClick (View.java:4780) à android.view.View $ PerformClick.run (View.java:19866) à android.os.Handler.handleCallback (Handler.java:739) à android.os.Handler.dispatchMessage (Handler.java:95) à android.os.Looper.loop (Looper. java: 135) at android.app.ActivityThrea d.main (ActivityThread.java:5254) à java.lang.reflect.Method.invoke (méthode native) à java.lang.reflect.Method.invoke (Method.java:372) à com.android.internal .os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:903) à com.android.internal.os.ZygoteInit.main (ZygoteInit.java:698)
Ce sont mes codes.
Ceci est mon activité principale
public void onClick(View v) {
final Integer newSleep = sleep;
sleep_repo repo = new sleep_repo(MainActivity.this);
others sleep = new others();
sleep.sleep = Recent_f_id;
sleep.sleep=newSleep;
repo.delete1(sleep);
Recent_f_id = repo.insert(sleep);
Toast.makeText(getApplicationContext(),
newSleep + " has been added", Toast.LENGTH_LONG)
.show();
d.dismiss();
}
alors que c'est mon sleep_repo.java
public void delete1(others sleep) {
// db.delete(String tableName, String whereClause, String[] whereArgs);
// If whereClause is null, it will delete all rows.
SQLiteDatabase db = dbHelper.getWritableDatabase(); // helper is object extends SQLiteOpenHelper
db.delete(getDateTime(),null,null);
/*db.delete(getDateTime(),others.KEY_ID+"=?",new String[] { String.valueOf(sleep) });*/
db.close(); // Closing database connection
}
alors que c'est mon others.java
public class others {
// Labels table name
public static final String TABLE = "others";
// Labels Table Columns names
public static final String KEY_ID = "id";
public static final String KEY_sleep = "sleep";
public static final String KEY_smoke = "smoke";
public static final String KEY_exercise = "exercise";
// property help us to keep data
public int Recent_f_id;
public Integer id;
public Integer sleep;
public Integer smoke;
public String exercise;
}
et ceci est mes dates .java
public class Dates extends SQLiteOpenHelper {
//version number to upgrade database version
//each time if you Add, Edit table, you need to change the
//version number.
private static final int DATABASE_VERSION = 4;
public static String getDateTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyyMMdd", Locale.getDefault());
Date date = new Date();
return dateFormat.format(date);
}
// Database Name
private static final String DATABASE_NAME = getDateTime();
public Dates(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//All necessary tables you like to create will create here
String CREATE_TABLE_meals = "CREATE TABLE " + meals.TABLE + "("
+ meals.KEY_breakfast + " TEXT, "
+ meals.KEY_lunch + " TEXT, "
+ meals.KEY_dinner + " TEXT, "
+ meals.KEY_other + " TEXT)";
String CREATE_TABLE_drinks = "CREATE TABLE " + drinks.TABLE + "("
+ drinks.KEY_alcoholic + " TEXT, "
+ drinks.KEY_water + " INTEGER)";
String CREATE_TABLE_others = "CREATE TABLE " + others.TABLE + "("
+ others.KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ others.KEY_sleep + " TEXT, "
+ others.KEY_smoke + " INTEGER, "
+ others.KEY_exercise + " INTEGER)";
db.execSQL(CREATE_TABLE_meals);
db.execSQL(CREATE_TABLE_drinks);
db.execSQL(CREATE_TABLE_others);
}
Je réalise mon erreur, qui est db.delete (getDateTime(), null, null); qui doit être db.delete (other.TABLE, others.KEY_sleep, null); Mais merci pour votre réponse, à cause de votre réponse, je ne me rendrai pas compte de mon erreur. Je garderai aussi dans ma tête ta réponse. Merci mec! –