에 가능한 복제를 날짜 기능을 추가하는 방법 : 내가 데이터베이스에 이름, 암호 등을 저장하는 응용 프로그램을 개발하고 있어요
How to insert a SQLite record with a datetime set to ‘now’ in Android application?SQLite는
. 또한 데이터베이스에 현재 날짜와 시간을 저장하고 나중에 다시 검색하려고합니다. SQLite 데이터베이스에 날짜와 시간을 저장하는 방법을 해독 할 수 없습니다. 내가 datetime 함수를 사용해야합니까 ?? 그렇다면 내 진행 예제에 추가하는 방법. 도와주세요.
미리 감사드립니다.
public class DBAdapter{public static final String ROWID = "_id";
public static final String NAME = "name";
public static final String EMAIL = "email";
public static final String PASSWORD = "password";
public static final String TYPE = "type";
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "primus_db";
private static final String DATABASE_TABLE = "user_db";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE = "create table user_db (_id integer primary key autoincrement, "
+ "name text not null, "
+ "email text not null, "
+ "password text not null," + "type text not null);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
/**
*
*/
public DBAdapter(Context ctx) {
this.context = ctx;
this.DBHelper = new DBAdapter.DatabaseHelper(this.context);
}
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(DATABASE_CREATE);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS contacts");
onCreate(db);
}
}
// ---opens the database---
public DBAdapter open() throws SQLException {
db = DBHelper.getWritableDatabase();
return this;
}
// ---closes the database---
public void close() {
DBHelper.close();
}
// ---insert a contact into the database---
public long insertContact(String name, String email, String password,
String type) {
ContentValues initialValues = new ContentValues();
initialValues.put(NAME, name);
initialValues.put(EMAIL, email);
initialValues.put(PASSWORD, password);
initialValues.put(TYPE, type);
return db.insert(DATABASE_TABLE, null, initialValues);
}
// ---retrieves all the contacts---
public Cursor getAllContacts() {
return db.query(DATABASE_TABLE, new String[] { ROWID, NAME, EMAIL,
PASSWORD, TYPE }, null, null, null, null, null);
}
}