Android应用程序中没有记录保存在DB中
在我的android应用程序中,每次执行某个操作时,我都将记录保存在DB中。代码如下:Android应用程序中没有记录保存在DB中,android,sqlite,android-sqlite,Android,Sqlite,Android Sqlite,在我的android应用程序中,每次执行某个操作时,我都将记录保存在DB中。代码如下: Cursor histCurr = db.rawQuery("select * from HistStore order by seqNum", null); Log.d("DBHIST", histCurr.getCount() +" rows in DB0."); db.beginTransaction(); long ret = db.insert("HistStore"
Cursor histCurr = db.rawQuery("select * from HistStore order by seqNum", null);
Log.d("DBHIST", histCurr.getCount() +" rows in DB0.");
db.beginTransaction();
long ret = db.insert("HistStore", null, newValues);
db.endTransaction();
if(ret<0){
Log.d("DBHIST", "\r\n!!! Error to save history into DB!!!\r\n");
}else{
Log.d("DBHIST", ret+" rows inserted.");
histCurr = db.rawQuery("select * from HistStore order by seqNum", null);
Log.d("DBHIST", histCurr.getCount() +" rows in DB1.");
}
Cursor histCurr=db.rawQuery(“按seqNum从HistStore订单中选择*”,null);
d(“DBHIST”,histCurr.getCount()+“DB0中的行”);
db.beginTransaction();
long ret=db.insert(“HistStore”,null,newValues);
db.endTransaction();
如果(ret自启动事务以来,您需要将其标记为成功,以使更改保持不变
尝试这样做:
Cursor histCurr = db.rawQuery("select * from HistStore order by seqNum", null);
Log.d("DBHIST", histCurr.getCount() +" rows in DB0.");
db.beginTransaction();
long ret = -1;
try{
ret = db.insert("HistStore", null, newValues);
db.setTransactionSuccessful();
}
catch(Exception e){
}
finally{
db.endTransaction();
}
if(ret<0){
Log.d("DBHIST", "\r\n!!! Error to save history into DB!!!\r\n");
}else{
Log.d("DBHIST", ret+" rows inserted.");
histCurr = db.rawQuery("select * from HistStore order by seqNum", null);
Log.d("DBHIST", histCurr.getCount() +" rows in DB1.");
}
Cursor histCurr=db.rawQuery(“按seqNum从HistStore订单中选择*”,null);
d(“DBHIST”,histCurr.getCount()+“DB0中的行”);
db.beginTransaction();
长ret=-1;
试一试{
ret=db.insert(“HistStore”,null,newValues);
db.setTransactionSuccessful();
}
捕获(例外e){
}
最后{
db.endTransaction();
}
如果(retarso,OP在语义上不正确。变量ret
包含成功插入行的id。因此表达式Log.d(“DBHIST”,ret+“rows inserted.”)在语义上不正确,则它听起来应该像“row with id=“+ret+”inserted”
。没错,只要ret的值>=0,就知道它的值并没有多大帮助。不过,他似乎正在查询数据库并检查它的计数