创建表时遇到问题。错误说没有这样的表,即使我的查询正确无误,但我已经检查了很多次。
public class DatabaseOperations extends SQLiteOpenHelper {
public static final int database_version = 1;
public String CREATE_QUERY = "CREATE TABLE"+TableData.TABLE_NAME+"("+TableData.USER_NAME+" TEXT, "+TableData.USER_PASS+" TEXT);";
public DatabaseOperations(Context context) {
super(context,TableData.DATABASE_NAME, null, database_version);
Log.d("Database Operations", "Database Created");
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_QUERY);
Log.d("Database Operations", "Table Created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
这是Logcat:
08-08 18:00:19.008 2036-2043/com.example.fani.sqlitetest W/art﹕ Suspending all threads took: 12.494ms
08-08 18:00:19.667 2036-2036/com.example.fani.sqlitetest D/Database Operations﹕ Database Created
08-08 18:00:19.673 2036-2036/com.example.fani.sqlitetest E/SQLiteLog﹕ (1) no such table: users_info
08-08 18:00:19.679 2036-2036/com.example.fani.sqlitetest E/SQLiteDatabase﹕ Error inserting user_pass=fani user_name=farhan
android.database.sqlite.SQLiteException: no such table: users_info (code 1): , while compiling: INSERT INTO users_info(user_pass,user_name) VALUES (?,?)
最佳答案
您的查询不正确。 CREATE TABLE
和表名之间没有空格。
尝试这个:
String CREATE_QUERY = "CREATE TABLE "+TableData.TABLE_NAME+" ("+TableData.USER_NAME+" TEXT, "+TableData.USER_PASS+" TEXT);";