在我的數據庫表中,我有一個日期列和其他2列。
我想寫它檢索已根據系統保存日期today
,數據的查詢。SQLite數據庫查詢
public class UserDbHelper extends SQLiteOpenHelper {
public static final String DATABASENAME = "DATABASENAME2";
public static final int DB_VERSION = 1;
public UserDbHelper(Context context)
{
super(context,DATABASENAME,null,DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS BluetoothDevice (Device VARCHAR , Address VARCHAR , Date VARCHAR);");
}
public List<BluetoothDevice> getItemFromDatabase(SQLiteDatabase sqLiteDatabase) {
List<BluetoothDevice> result = new ArrayList<>();
// query database elements
Cursor c = sqLiteDatabase.rawQuery("Select * from BluetoothDevice;", null);
while (c.moveToNext()) {
Date v = new Date();
v.setTime(c.getInt(c.getColumnIndex("Date")) * 1000);
Date date = new Date();
date.setTime(Long.valueOf(c.getString(c.getColumnIndex("Date"))));
result.add(
new BluetoothDevice(
c.getString(c.getColumnIndex("Device")),
c.getString(c.getColumnIndex("Address")),
date
)
);
}
c.close();
return result;
}
public void store(List<BluetoothDevice> data,SQLiteDatabase sqLiteDatabase) {
for (BluetoothDevice value : data) {
String s = String.valueOf(new Date().getTime());
//insert in database
sqLiteDatabase.execSQL("INSERT INTO BluetoothDevice VALUES(?,?,?,?);", new String[]{value.name, value.address, s});
}
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
問題是什麼?如果您想** **的東西,不是請說明你已盡力讓這 –
什麼,我想你想'c.getLong(c.getColumnIndex(「DATE」))' –
我想根據從數據庫retrive數據當前日期 –