I use SQLiteOpenHelper
in my project and when I use add_leader method everything works, but when I use add_Person method it returns false. This is second instance of sqlite.
I use manjaro 18 linux
Any help please?
public class SqliteHelper extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("CREATE TABLE " + START+ "("+KIND+" text) ");
sqLiteDatabase.execSQL("CREATE TABLE " + PERRSON + "("+ID_PER+" INTEGER PRIMARY KEY AUTOINCREMENT ,"
+FULLNAME_PER+" text,"+BIRTH_DAY_PER+"text," +BIRTH_MONTH_PER+" text,"+BIRTH_YEAR_PER+" text,"
+LEVEL_EDUCATION+" text,"+MOY_ONE+" text,"+MOY_TWO+" text,"+MOY_THREE+"text) ");
sqLiteDatabase.execSQL("CREATE TABLE " + LEADER + "("+ID_LEADER+" INTEGER PRIMARY KEY AUTOINCREMENT ,"+FULLNAME_LDR+" text,"+
BIRTH_DAY_LDR+" text,"+BIRTH_MONTH_LDR+" text,"+BIRTH_YEAR_LDR+" text) ");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
sqLiteDatabase.execSQL(" DROP TABLE IF EXISTS " + START);
sqLiteDatabase.execSQL(" DROP TABLE IF EXISTS " + PERRSON);
sqLiteDatabase.execSQL(" DROP TABLE IF EXISTS " + LEADER);
onCreate(sqLiteDatabase);
}
public boolean add_Person(String name, String date_day, String date_month, String date_year,
String level,String moy1,String moy2,String moy3) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(FULLNAME_PER, name);
cv.put(BIRTH_DAY_PER, date_day);
cv.put(BIRTH_MONTH_PER, date_month);
cv.put(BIRTH_YEAR_PER, date_year);
cv.put(LEVEL_EDUCATION, level);
cv.put(MOY_ONE, moy1);
cv.put(MOY_TWO, moy2);
cv.put(MOY_THREE, moy3);
long results = db.insert(PERRSON, null, cv);
db.close();
if (results == -1) return false;
else return true;
}
public boolean add_leader(String fullname, String date_day, String date_month, String date_year) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(FULLNAME_LDR, fullname);
cv.put(BIRTH_DAY_LDR, date_day);
cv.put(BIRTH_MONTH_LDR, date_month);
cv.put(BIRTH_YEAR_LDR, date_year);
long results = db.insert(LEADER, null, cv);
db.close();
if (results == -1) return false;
else return true;
}
Your PERRSON table is not created because there are spacing issues in create table query. found spacing issue in these column BIRTH_DAY_PER,MOY_THREE.
replace this section of code
sqLiteDatabase.execSQL("CREATE TABLE " + PERRSON + "("+ID_PER+" INTEGER PRIMARY KEY AUTOINCREMENT ,"
+FULLNAME_PER+" text,"+BIRTH_DAY_PER+"text," +BIRTH_MONTH_PER+" text,"+BIRTH_YEAR_PER+" text,"
+LEVEL_EDUCATION+" text,"+MOY_ONE+" text,"+MOY_TWO+" text,"+MOY_THREE+"text) ");
with this
sqLiteDatabase.execSQL("CREATE TABLE " + PERRSON + "("+ID_PER+" INTEGER PRIMARY KEY AUTOINCREMENT ,"
+FULLNAME_PER+" text,"+BIRTH_DAY_PER+" text," +BIRTH_MONTH_PER+" text,"+BIRTH_YEAR_PER+" text,"
+LEVEL_EDUCATION+" text,"+MOY_ONE+" text,"+MOY_TWO+" text,"+MOY_THREE+" text)");
sqLiteDatabase.execSQL("CREATE TABLE " + PERRSON + "(" + ID_PER + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ FULLNAME_PER + " text," + BIRTH_DAY_PER + " text," + BIRTH_MONTH_PER + " text," + BIRTH_YEAR_PER + " text,"
+ LEVEL_EDUCATION + " text," + MOY_ONE + " text," + MOY_TWO + " text," + MOY_THREE + " text" + ")");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.