问题
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