我无法创建表格。它显示数据库已创建,我也可以插入一行,但不会创建该表。
public class DatabaseOperations extends SQLiteOpenHelper {
public static final int Database_version = 2;
public static final String Tag = DatabaseOperations.class.getSimpleName();
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TableData.TableInfo.TABLE_NAME + " (" +
TableData.TableInfo.USER_ID + " INTEGER PRIMARY KEY," +
TableData.TableInfo.USER_PASS +" TEXT "+ "," +
TableData.TableInfo.USER_EMAIL +" TEXT "+ ");";
public DatabaseOperations(Context context) {
super(context, TableData.TableInfo.DATABASE_NAME, null,Database_version);
Log.d("Tag", "Database created");
}
@Override
public void onCreate(SQLiteDatabase sdb) {
sdb.execSQL(SQL_CREATE_ENTRIES);
Log.d("Tag", "Table created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void putInformation(DatabaseOperations drop, String name, String pass, String email) {
SQLiteDatabase SQ = drop.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TableData.TableInfo.USER_ID, name);
cv.put(TableData.TableInfo.USER_PASS, pass);
cv.put(TableData.TableInfo.USER_EMAIL, email);
long k = SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
Log.d("Tag", "inert a row");
}
public Cursor getInformation(DatabaseOperations dop) {
SQLiteDatabase SQ = dop.getReadableDatabase();
String[] coloumns = {TableData.TableInfo.USER_ID, TableData.TableInfo.USER_PASS, TableData.TableInfo.USER_EMAIL};
Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME, coloumns, null, null, null, null, null);
return CR;
}
}
答案 0 :(得分:1)
您在CREATE TABLE中的,
和USER_EMAIL
列之间缺少USER_PASS
。
添加后,您可以卸载应用程序以重新创建数据库。 When is SQLiteOpenHelper onCreate() / onUpgrade() run?
答案 1 :(得分:0)
您错过了USER PASS类型中的逗号。卸载应用程序并在每次向sqlite数据库添加新内容时再次安装它,因为表结构已更改。因此您需要重新安装新应用程序。
代码应该是这样的
private static final String SQL_CREATE_ENTRIES = " CREATE TABLE" + TableData.TableInfo.TABLE_NAME +" (" + TableData.TableInfo.USER_ID +" INTEGER PRIMARY KEY," + TableData.TableInfo.USER_PASS +" TEXT," +"," + TableData.TableInfo.USER_EMAIL +" TEXT" +")&#34 ;;