简体   繁体   中英

Avoid sqliteAssetHelper to log error

Hi guys i'have problem with this little block of code

// Insert a new contact in database
    public void insertInSignature(String TITLE_SI) {
        try {
            // Open Android Database
            db = databaseHelper.getWritableDatabase();
            ContentValues initialValues = new ContentValues();
            initialValues.put("TITLE_SI", TITLE_SI);
            db.insert("DELIVERY_SLIP", null, initialValues);
        } catch (SQLException sqle) {
            Log.e(TAG, "insertUser Error");
            Log.e(TAG, "Exception : " + sqle);
        } finally {
            // Close Android Database
            databaseHelper.close();
        }
    }

I have unique constraint on my table "DELIVERY_SLIP

So , when i'm trying to insert some row which already exist , it return some error like "Oh shit , you're inserting the same , i'm sorry men , i can't do it"

http://cdn.imghack.se/images/3b51afd07d1f1a8bd021c9e9dfc57e98.png

Here my log

It's this line

databaseHelper.close();

When database helper close , this return the log. I just want to avoid to log it, I already tested with a tryCatch on sqliteConstraintException But, nothing worked. Thanks by advance

代替insert() ,将insertWithOnConflict()与一些适合您的使用的冲突解决算法一起使用,例如SQLiteDatabase.CONFLICT_IGNORE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM