朋友,
我写了以下sqlite insert语句,这似乎是错误的。 在插入行之前,我正在检查记录是否存在,然后不要插入(ATM数据超过600条记录)
为atm的cache.select 1中的此sql语句的database.no空间的已编译的sql语句缓存达到最大大小,其中atmid = 251请更改您的sql语句以使用“?”对于bindargs而不是
public void addAtm(ATM atm)
{
db.execSQL("INSERT INTO " + AtmsTable.NAME +
"(" +AtmsTable.COL_ID + ","
+AtmsTable.COL_BankID +","
+ AtmsTable.COL_BankNAME+","
+ AtmsTable.COL_BankPhone+","
+ AtmsTable.COL_BankAddress+","
+ AtmsTable.COL_BankCoordinates+","
+ AtmsTable.COL_BankCity+","
+ AtmsTable.COL_BankWebaddress+") Values ("
+atm.getAtmID()+","
+atm.getBankID()
+ ",'" + atm.getBankName().trim()
+"','" + atm.getPhone()
+"','" + atm.getAddress()
+"','" + atm.getCoordinates()
+"','" + atm.getCity()
+"','" + atm.getWebAddress()+ "');");
}
和
public boolean atmExists(int atmId)
{
OpenIfNotOpened();
Cursor cursor = db.rawQuery("select 1 from " + AtmsTable.NAME +" where " + AtmsTable.COL_ID + "=" + atmId,null);
boolean exists = (cursor.getCount() > 0);
cursor.close();
return exists;
}
我收到以下错误消息
任何帮助将不胜感激。
答案 0 :(得分:1)
public void execSQL(String sql)
自:API级别1执行单个 SQL语句不是SELECT或 返回的任何其他SQL语句 数据。它没有办法归还任何东西 数据(例如受影响的人数) 行)。相反,你被鼓励 使用insert(String,String, ContentValues),update(String, ContentValues,String,String [])等 al,如果可能的话。
只需使用:
ContentValues vals = new ContentValues();
vals.put(AtmsTable.COL_BankID, atm.getBankID());
vals.put(AtmsTable.COL_BankNAME, atm.getBankName().trim());
/...
if(db.update(AtmsTable.NAME, vals, AtmsTable.COL_ID + "=?", new String[]{Integer.toString(atm.getAtmID())}) == 0){
vals.put(AtmsTable.COL_ID, atm.getAtmID());
db.insert(AtmsTable.NAME, null, vals);
}