简体   繁体   English

避免sqliteAssetHelper记录错误

[英]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 我对表“ 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 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. 我只是想避免记录它,我已经在sqliteConstraintException上使用tryCatch进行了测试,但是没有任何效果。 Thanks by advance 预先感谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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