How to get errors details from android.database.SQLException?

孤街浪徒 提交于 2020-01-15 05:38:10

问题


I have a database in my android app with two separate columns that have a UNIQUE constraint. When entering data and an SQLException exception is thrown I want to know which field's unique constraint was violated so I can take appropriate action.


回答1:


The class java.lang.SQLException on which android.database.SQLException is based has methods int getErrorCode() and String getSQLState() which should be able to help you get details.




回答2:


Database constraints are mostly intended to catch programming errors.

If detecting duplicates is part of your app's logic, you should manually check for them.



来源:https://stackoverflow.com/questions/35637570/how-to-get-errors-details-from-android-database-sqlexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!