<small id='0pMrU'></small><noframes id='0pMrU'>

<i id='0pMrU'><tr id='0pMrU'><dt id='0pMrU'><q id='0pMrU'><span id='0pMrU'><b id='0pMrU'><form id='0pMrU'><ins id='0pMrU'></ins><ul id='0pMrU'></ul><sub id='0pMrU'></sub></form><legend id='0pMrU'></legend><bdo id='0pMrU'><pre id='0pMrU'><center id='0pMrU'></center></pre></bdo></b><th id='0pMrU'></th></span></q></dt></tr></i><div id='0pMrU'><tfoot id='0pMrU'></tfoot><dl id='0pMrU'><fieldset id='0pMrU'></fieldset></dl></div>
    <legend id='0pMrU'><style id='0pMrU'><dir id='0pMrU'><q id='0pMrU'></q></dir></style></legend>
  • <tfoot id='0pMrU'></tfoot>

        <bdo id='0pMrU'></bdo><ul id='0pMrU'></ul>
      1. SQLiteConstraintException 不要进入 catch

        时间:2023-07-08
        <tfoot id='jHdU5'></tfoot>

          <tbody id='jHdU5'></tbody>
        <legend id='jHdU5'><style id='jHdU5'><dir id='jHdU5'><q id='jHdU5'></q></dir></style></legend>

        <small id='jHdU5'></small><noframes id='jHdU5'>

      2. <i id='jHdU5'><tr id='jHdU5'><dt id='jHdU5'><q id='jHdU5'><span id='jHdU5'><b id='jHdU5'><form id='jHdU5'><ins id='jHdU5'></ins><ul id='jHdU5'></ul><sub id='jHdU5'></sub></form><legend id='jHdU5'></legend><bdo id='jHdU5'><pre id='jHdU5'><center id='jHdU5'></center></pre></bdo></b><th id='jHdU5'></th></span></q></dt></tr></i><div id='jHdU5'><tfoot id='jHdU5'></tfoot><dl id='jHdU5'><fieldset id='jHdU5'></fieldset></dl></div>
          • <bdo id='jHdU5'></bdo><ul id='jHdU5'></ul>

                  本文介绍了SQLiteConstraintException 不要进入 catch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我运行该代码时,我在 db.insert 中有一个异常:

                  When I run that code I have inside the db.insert an exception:

                  08-29 15:40:17.519: E/SQLiteDatabase(3599): android.database.sqlite.SQLiteConstraintException: column date is not unique (code 19)
                  

                  这很正常,因为我已经将该值作为键.所以在那种情况下,我会捕获 SQLiteConstraintException 但我在运行代码时永远不会进入捕获中.

                  Which is normal, because I already have that value as a key. So in that case I do a catch of SQLiteConstraintException but I never get inside the catch when I run the code.

                  我做错了什么?

                             try {
                                  db.insert(TABLE_STATISTICS, null, values);
                              } catch (SQLiteConstraintException e) {
                                  Log.d("entered", "entered the exception");
                                  ContentValues valuesUp = new ContentValues();
                                  valuesUp.put((isMT ? KEY_MT : KEY_MO), change); 
                                  db.update(TABLE_STATISTICS, valuesUp, KEY_DATE + "=?",
                                          new String[] { message_date });
                              }
                  

                  谢谢.

                  整个日志:

                  08-29 15:55:55.870: E/SQLiteDatabase(3828): Error inserting MO=0 date=2012-08-08 MT=1
                  08-29 15:55:55.870: E/SQLiteDatabase(3828): android.database.sqlite.SQLiteConstraintException: column date is not unique (code 19)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at xx.xxx.xxx.xx.xxxx.StatisticsHolderDay.updateCounterNextStep(StatisticsHolderDay.java:124)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at xx.xxx.xxx.xx.xxxx.StatisticsHolderDay.updateCounter(StatisticsHolderDay.java:102)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at xx.xxx.xxx.xx.xxxx.LastMonthActivity.onStart(LastMonthActivity.java:146)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.Activity.performStart(Activity.java:5018)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.os.Handler.dispatchMessage(Handler.java:99)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.os.Looper.loop(Looper.java:137)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread.main(ActivityThread.java:4745)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at java.lang.reflect.Method.invokeNative(Native Method)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at java.lang.reflect.Method.invoke(Method.java:511)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                  08-29 15:55:55.870: E/SQLiteDatabase(3828):     at dalvik.system.NativeStart.main(Native Method)
                  

                  推荐答案

                  使用 db.insertOrThrow() 代替.

                  这篇关于SQLiteConstraintException 不要进入 catch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android Room持久性库@Update不起作用 下一篇:Android:onUpgrade 不在数据库升级时调用

                  相关文章

                1. <tfoot id='PDE1A'></tfoot>
                2. <legend id='PDE1A'><style id='PDE1A'><dir id='PDE1A'><q id='PDE1A'></q></dir></style></legend>
                    <bdo id='PDE1A'></bdo><ul id='PDE1A'></ul>

                      <i id='PDE1A'><tr id='PDE1A'><dt id='PDE1A'><q id='PDE1A'><span id='PDE1A'><b id='PDE1A'><form id='PDE1A'><ins id='PDE1A'></ins><ul id='PDE1A'></ul><sub id='PDE1A'></sub></form><legend id='PDE1A'></legend><bdo id='PDE1A'><pre id='PDE1A'><center id='PDE1A'></center></pre></bdo></b><th id='PDE1A'></th></span></q></dt></tr></i><div id='PDE1A'><tfoot id='PDE1A'></tfoot><dl id='PDE1A'><fieldset id='PDE1A'></fieldset></dl></div>
                    1. <small id='PDE1A'></small><noframes id='PDE1A'>