以下是我写的sqlite表的声明;
db.execSQL("create table if not exists data( d text, hr integer, rrInterval real, acc_x real, acc_y real, acc_z real);");
所以这就是表data
的样子。
data{
d text,
hr integer,
rrInterval real,
acc_x real,
acc_y real,
acc_z real
}
我得到了一些用Microsoft Band 2测量的变量,该变量存储在以下变量中;我检查了所有这些变量从MS频段获取正确的数据。
String d;
int heartRate;
double rrInterval;
float acc_x, acc_y, acc_z;
因此,这是用于将数据存储在SQLite数据库中。
MyOpenHelper helper = new MyOpenHelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL("create table if not exists data( d text, hr integer, rrInterval real, acc_x real, acc_y real, acc_z real);");
/* some other codes irrelevant to DB */
db.execSQL("insert into data(d, hr, rrInterval, acc_x, acc_y, acc_z) values ('" +
d + "', " + //date
Integer.toString(heartRate) + ", " + //hr
Double.toString(rrInterval)+ ", " + //rrInterval
Float.toString(acc_x) + ", " + //acc_x
Float.toString(acc_y) + ", " + //acc_y
Float.toString(acc_z) + //acc_z
");");
据我所知,Java和Sqlite上都没有语法错误。但是Android Studio返回错误,这不是insert ...
语句。我如何弄清楚如何解决此问题?
而不是使用这种方法尝试使用contentValues的使用易于使用。
ContentValues cv = new ContentValues();
cv.put("d", DATA_NEEDED_TO_INSERT);
cv.put("hr", DATA_NEEDED_TO_INSERT);
cv.put("rrInterval", DATA_NEEDED_TO_INSERT);
cv.put("acc_x", DATA_NEEDED_TO_INSERT);
cv.put("acc_y", DATA_NEEDED_TO_INSERT);
cv.put("acc_z", DATA_NEEDED_TO_INSERT);
SQLiteDatabase db = getWritableDatabase();
db.insert(TABLE_NAME, null, cv); // insert function
db.close(); // dont forget to close your db
不要忘记db.close((;过程之后,欢呼