Sqlite constraint failed error in android project

My table structure is as shown below

CREATE TABLE MCARE_HOUSE_DETAILS (
                HOUSE_DTL_ID VARCHAR(20) NOT NULL,
                HOUSE_SRV_DTL_ID VARCHAR(20) NULL,
                WARD_ID VARCHAR(20)  NOT NULL,
                HOUSE_NO VARCHAR(50) NOT NULL,
                HOUSE_NAME VARCHAR(50),
                ADDRESS VARCHAR(300),
                HOUSE_TYPE VARCHAR(20) ,
                ELECTRICITY CHAR(1),
                LATRINE_TYPE VARCHAR(20) ,
                WATER_SOURCE VARCHAR(20) ,
                WATER_STORAGE_FACILITY INTEGER,
                WASTE_DISPOSAL_SOLID VARCHAR(20) ,
                WASTE_DISPOSAL_LIQUID VARCHAR(20) ,
                SURVEY_DATE CHAR(10),
                CREATED_USER_ID VARCHAR(20) ,
                CREATED_DATE CHAR(19),
                MODIFIED_USER_ID VARCHAR(20) ,
                MODIFIED_DATE CHAR(19),
                UPLOAD_STATUS CHAR(1),
                INSTITUTION_ID VARCHAR(10),
                NEW_WARD_ID VARCHAR(20) ,
                NEW_HOUSE_NO VARCHAR(50),
                UNIQUE_HOUSE_NO VARCHAR(50),
                PRIMARY KEY (HOUSE_DTL_ID))

Insert query block is as below

  openDB=DBConnection.getInstance(context).openDataBase();      
SQLiteStatement statement = openDB.compileStatement("INSERT INTO MCARE_HOUSE_DETAILS (HOUSE_DTL_ID,WARD_ID,HOUSE_NO) VALUES(?,?,?);");   
statement.bindString(1,houseId);  
statement.bindString(1,wardId);  
statement.bindString(2,houseNumber); 
statement.executeInsert(); 

and the values inserted are houseId=bp,wardId=199,houseNumber=Test

and I got the following error on insertion

: android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed

I can't insert even a single row in this table

Plz help.

Answers


It's because you set the HOUSE_NO to "". Your statement doesn't bind parameter #3.

statement.bindString(1,houseId);  
statement.bindString(1,wardId);  
statement.bindString(2,houseNumber);

Try this one:

statement.bindString(1,houseId);  
statement.bindString(2,wardId);  
statement.bindString(3,houseNumber);

Better to use ContentValues . it easy to use in android.

            ContentValues values = new ContentValues();
    values.put(Database_COLUMN_NAME, "VALUE");
             SQLiteDatabase database;
            database.insert(Database_TABLE_NAME, "",values);

it help you.

Thanks


Need Your Help

ng-repeat with no parent container

javascript jquery jquery-ui angularjs

i'm using Jquery Accordion http://jqueryui.com/accordion/

Press button in listView adapter to get data in this row

android android-listview baseadapter

I have a listView that shows data that in sqlite, I'm using baseAdapter.