以下是我写的SQLite表的声明语句;Android中的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 Band获取正确的数据。
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 ...
声明。我怎样才能弄清楚如何解决这个问题?
'“但Android Studio返回错误”'它返回什么错误?为什么不使用'SQLiteDatabase#insert()'方法? – pskink
你的代码对我来说工作的很好。我使用Android Studio 2.3.2 – sanemars