I dodaje ciąg znaków, datę, czas i int wartości do sqlite bazy danych przy użyciu tego koduget ciąg, data, godzina i int z sqlite bazy danych w Android
void addRemAction(RemActions remaction) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_ACTOINS_TITLE, remaction.getTitle()); // Action title
values.put(KEY_ACTIONS_MSG, remaction.getMsg()); // action msg
values.put(KEY_ACTIONS_DATE, dateFormat.format(new Date())); // action date
values.put(KEY_ACTIONS_TIME, remaction.getTime()); // action time
values.put(KEY_ACTIONS_PLACE_LONG, remaction.getPlong()); // action place long
values.put(KEY_ACTIONS_PLACE_LAT, remaction.getPlat()); // action place lat
// Inserting Row
db.insert(TABLE_ACTIONS, null, values);
db.close(); // Closing database connection
i to jest mój kod, aby pobrać go
RemActions getRemAction(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_ACTIONS, new String[] {KEY_ACTOINS_TITLE, KEY_ACTIONS_MSG, KEY_PLACES_NAME, KEY_ACTIONS_DATE, KEY_ACTIONS_TIME}, KEY_ACTIONS_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
RemActions remActions = new RemActions(cursor.getString(0),
cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(4));
// return remActions
return remActions;
teraz mój ide daje mi błędy, ponieważ 4 argument w moim konstruktorze dla klasy RemAction jest typu Date z klasy java.util.date.
Moje pytanie brzmi: "jak ustawić kursor, aby uzyskać format daty?"
chory b zadowolony, w celu zapewnienia dodatkowego kodu na życzenie
witamy w SO..close db, a także kursor w metodzie getRemAction() da wyjątek. – TheFlash
Możesz także użyć 'cursor.getDate (1)', aby uzyskać datę. Nie używałem ich od jakiegoś czasu, ale powinno to być coś takiego: http://www.coderanch.com/t/445539/JDBC/databases/retrieve-Date-JDBC-sql –
@TheDarkKnight Uwaga: Android nie nie używaj JDBC i nie ma getDate w SQLite. – m0skit0