SQLiteDatabase execSQL

时间:2014-11-22 22:00:46

标签: java android sqlite android-sqlite sqliteopenhelper

我在Android中为我的数据库创建新查询时遇到了问题。

(1) table reg_info has no column named user_pass

Error inserting user_pass=qq user_name=aa
android.database.sqlite.SQLiteException: table reg_info has no column named user_pass (code 1): , while compiling: INSERT INTO reg_info(user_pass,user_name) VALUES (?,?)

这是我的DatabaseOperations。

public class DatabaseOperations extends SQLiteOpenHelper {
public static final int database_version = 1;
public String CREATE_QUERY = "CREATE TABLE "
        + TableInfo.TABLE_NAME 
        + "("
        + TableInfo.USER_NAME + " TEXT,"
        + TableInfo.USER_PASS + " TEXT"
        + ");";

public DatabaseOperations(Context context) {
    super(context, TableInfo.DATABASE_NAME, null, database_version);
    // TODO Auto-generated constructor stub
    Log.d("Database operations", "Database created");
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    Log.d("peter", CREATE_QUERY);
    db.execSQL(CREATE_QUERY);
    Log.d("Database operations", "Database created");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}

public void putInformation(DatabaseOperations dop, String name, String pass) {
    SQLiteDatabase SQ = dop.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put(TableInfo.USER_NAME, name);
    cv.put(TableInfo.USER_PASS, pass);
    long k = SQ.insert(TableInfo.TABLE_NAME, null, cv);
    Log.d("Database operations", "One row inserted");
}

}

表资料:

public class TableData {

  public TableData() {

  }

  public static abstract class TableInfo implements BaseColumns {

    public static final String USER_NAME = "user_name";
    public static final String USER_PASS = "user_pass";
    public static final String DATABASE_NAME = "user_info";
    public static final String TABLE_NAME = "reg_info";

  }

}

我的CREATE_QUERY字符串有什么问题?我试图弄清楚好几个小时但到目前为止还没有解决方案!

0 个答案:

没有答案