這個類將創建一個table..You可以創建必填字段編輯這個類。
public class TableCreater extends SQLiteOpenHelper
{
public static final String DATABASE_NAME = "userregister.db";
public static final int VERSION = 1;
public static final String TABLE_NAME = "USER_SESSION";
public static final String COLUMN_ID = "_id";
public static final String USER_ID = "user_id";
public static final String TABLE_CREATE =
"create table " + TABLE_NAME + " (" + COLUMN_ID
+ " integer primary key autoincrement," + USER_ID + " integer);";
public static final String FIRST_QUERY = "insert into " + TABLE_NAME
+ " (user_id) values(0);";
public loginchecker(Context context) {
super(context, DATABASE_NAME, null, VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
db.execSQL(FIRST_QUERY);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(loginchecker.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
這種方法將更新tables..You數據可以按照您的要求
public InsertingClass InsertID(int uid)
{
ContentValues values = new ContentValues();
values.put(loginchecker.USER_ID, uid);
long insertedId = database.insert(loginchecker.TABLE_NAME, null,
values);
Cursor cursor = database.query(loginchecker.TABLE_NAME, allColumnsLogin,
loginchecker.COLUMN_ID + " = " + insertedId, null, null,
null, null);
cursor.moveToFirst();
return cursorToModel(cursor);
}
ü使用qslite或MySQL的數據庫? – Zamani 2012-07-17 07:33:34
我想你需要一個數組來計算你的數據庫中的行數 – Zamani 2012-07-17 07:35:14