I have a class extends SQLiteOpenHelper and a database declared as:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + COL_TEMPERATURA
+ " TEXT, " + COL_UMIDITA + " TEXT," + COL_DATA + "DATETIME)");
}
now i would insert records inside it, but when i try to insert the last field (of DATETIME type) eclipse told me that i can't do it:
public void insertRecord(List<Object[]> list) throws ParseException {
String temperatura, umidita, data;
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
for (int i = 0; i < list.size(); i++) {
temperatura = String.valueOf(list.get(i)[0]);
umidita = String.valueOf(list.get(i)[1]);
data = String.valueOf(list.get(i)[2]);
// parsing data
DateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date data_date = dateformat.parse(data);
// insert into database
cv.put(COL_TEMPERATURA, temperatura);
cv.put(COL_UMIDITA, umidita);
cv.put(COL_DATA, data_date);
db.insert(TABLE_NAME, null, cv);
db.close();
}
because cv.put() takes as arguments only two strings. Now if i parse data_date variable into string, MySql automatically convert it in its correct format?