您好我将一些数据传递到sqlLite数据库,我想分别发送当前日期和时间。我对编程很陌生,所以任何帮助都会很糟糕。我检查过,其他数据正确存储。
public class DBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "vas_podatki.db";
public static final String TABLE_NAME = "podatki";
public static final String COL_1 = "ID";
public static final String COL_2 = "JAKOST";
public static final String COL_3 = "DAN";
public static final String COL_4 = "URA";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table "+ TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT, JAKOST INTEGER, DAN CURRENT_DATE , URA CURRENT_TIME )");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS"+ TABLE_NAME);
onCreate(db);
}
public boolean insertData(String jakost){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2,jakost);
long reuslt = db.insert(TABLE_NAME,null,contentValues);
if (reuslt == -1)
return false;
else
return true;
}
}
答案 0 :(得分:0)
private void addVacantEntry(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + MyDatabaseColums.VacantEntry.TABLE_NAME + " ("
+ MyDatabaseColums.VacantEntry.V_id + " INTEGER PRIMARY KEY, "
+ MyDatabaseColums.VacantEntry.Date + " NUMERIC);");
如果您想在Sqlite中保存日期时间,属性类型将为 NUMERIC
并将其存储在长
中获取日期时间喜欢这个
private long date_in_long() {
Calendar c = Calendar.getInstance();
c.set(Syear, Smonth, Sday, Shoure, Sminute);
long startDate = c.getTimeInMillis();
return startDate;
}