本文介绍了SQLiteConstraintException:错误code 19:约束失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解的异常时,我做了一个插件在我的SQLite数据库

I'm getting that exception when I do an insert in my SQLite database

下面code给我的异常:

The following code gives me the exception:

mDbHelper.createUser("pablo","a","a","a","a");

从mDbHelper(MyDbAdapter)在code:

The code from mDbHelper (MyDbAdapter):

private static final String USER_TABLE_CREATE = "CREATE TABLE user ( email varchar, password varchar, fullName varchar, mobilePhone varchar, mobileOperatingSystem varchar, PRIMARY KEY  (email))";

public long createUser(String email, String password, String fullName, String mobilePhone, String mobileOperatingSystem)
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put("email",email);
        initialValues.put("password",password);
        initialValues.put("fullName",fullName);
        initialValues.put("mobilePhone",mobilePhone);
        initialValues.put("mobileOperatingSystem",mobileOperatingSystem);
        return mDb.insert("user", null, initialValues);
    }

唯一的例外是在最后一行创建:返回mDb.insert(用户,空,initialValues​​);

推荐答案

您要插入重复电子邮件

另外推荐的方法是有一个 _ID 列作为主键,即使你不使用它。这样,在未来的使用,就像在一个适配器或列表的使用,你会不会有解决办法。

Plus the recommended way is to have a _ID column as primary key, even if you don't use it. This way on future uses, like use in a Adapter or List, you won't have to workaround.

这篇关于SQLiteConstraintException:错误code 19:约束失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 12:14