Android SQLite储存单引号出错的解决方法

2021-03-23 18:27:53.473 28763-28982/? E/SQLiteLog: (1) near "k1": syntax error
    
    
    --------- beginning of crash
2021-03-23 18:27:53.475 28763-28982/? E/AndroidRuntime: FATAL EXCEPTION: randomShelfUploadTimer
    Process: com.aplus.goodsshelves, PID: 28763
    android.database.sqlite.SQLiteException: near "k1": syntax error (code 1): , while compiling: update scan_record set is_upload = 1 where expressnum in ( 'YT5322921382500
    ','YT5320915492779
    ','YT9507368079604
    ','75427798072177
    ','4311937881630
    ','MMM={'k1':'769WF','k2':'769NA','k3':'001','k4':'T77','k5':'SF1326783694843','k6':'A1','k7':'c7515832'}
    ','SF1326783694843
    ','773078508974207
    ','YT4759286786382
    ','YT4690138831075
    ','YT4717590828219
    ' )
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:905)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:516)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31)
        at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1705)
        at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1636)
        at com.aplus.goodsshelves.activity.BatchGoodsPlaceActivity3.selectScanRecordAndUpload(BatchGoodsPlaceActivity3.java:778)
        at com.aplus.goodsshelves.activity.BatchGoodsPlaceActivity3.access$400(BatchGoodsPlaceActivity3.java:67)
        at com.aplus.goodsshelves.activity.BatchGoodsPlaceActivity3$2.run(BatchGoodsPlaceActivity3.java:193)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)

解决方法:

scanResult = scanResult.replaceAll("'", "''");

 

你可能感兴趣的:(Android,android)