我在创建表时遇到问题。错误说没有这样的表,即使我的查询是正确的,工作正常,我已经多次检查过。
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 (?,?)
答案 0 :(得分:1)
您的查询不对。 CREATE TABLE
和表名称之间没有空格。
试试这个:
String CREATE_QUERY = "CREATE TABLE "+TableData.TABLE_NAME+" ("+TableData.USER_NAME+" TEXT, "+TableData.USER_PASS+" TEXT);";
答案 1 :(得分:0)
将代码更改为:
private static final String CREATE_QUERY = "CREATE TABLE "+TableData.TABLE_NAME+" ("+TableData.USER_NAME+" TEXT, "+TableData.USER_PASS+" TEXT, "+")";