-2
package com.darkweb.android.amity_v13;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DbHelper extends SQLiteOpenHelper {
public static final String TAG = DbHelper.class.getSimpleName();
public static final String DB_NAME = "myapp.db";
public static final int DB_VERSION = 1;
public static final String USER_TABLE = "users";
public static final String COLUMN_ID = "Id";
public static final String COLUMN_EMAIL = "email";
public static final String COLUMN_PASS = "password";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_MOBILE = "mobile";
public static final String COLUMN_AID = "amizoneid";
/*
create table users(
id integer primary key autoincrement,
email text,
password text);
*/
public static final String CREATE_TABLE_USERS = "CREATE TABLE " + USER_TABLE + "("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMN_NAME + " TEXT,"
+ COLUMN_EMAIL + " TEXT,"+ COLUMN_MOBILE + " TEXT,"+ COLUMN_AID + " TEXT,"
+ COLUMN_PASS + " TEXT);";
public DbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_USERS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + USER_TABLE);
onCreate(db);
}
public void addUser(String email, String pass, String _name,String _mobile, String _id) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_EMAIL, String.valueOf(email));
values.put(COLUMN_PASS, String.valueOf(pass));
values.put(COLUMN_NAME, String.valueOf(_name));
values.put(COLUMN_MOBILE, String.valueOf(_mobile));
values.put(COLUMN_AID, String.valueOf(_id));
long id = db.insert(USER_TABLE, null, values);
db.close();
Log.d(TAG, "user inserted" + id);
}
public boolean getUser(String email, String pass){
//HashMap<String, String> user = new HashMap<String, String>();
String selectQuery = "select * from " + USER_TABLE + " where " +
COLUMN_EMAIL + " = " + "'"+email+"'" + " and "
+COLUMN_PASS + " = " + "'"+pass+"'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if (cursor.getCount() > 0) {
return true;
}
cursor.close();
db.close();
return false;
}
}
「我只是瞭解SQLite數據庫,我想從我的數據庫中檢索日期,並顯示在一個活動一個TextView,那怎麼辦? 給我的代碼,這樣我可以得到我的大學項目的一些幫助!SQLite數據庫數據retreive