Question

I have a problem with SQLite in android , I tried a simple insert in a table but I have an exception and in the exception I read this :

INSERT INTO Biblio(Auteur,Image,Livre) VALUES (?,?,?)

this is my method :

public void AddBook(Bibliothèque bibliothèque)
{
    SQLiteDatabase db=this.getWritableDatabase();
    //this.open();
    ContentValues values=new ContentValues();
    values.put(KEY_Auteur,bibliothèque.getNomAuteur());
    values.put(KEY_Livre,bibliothèque.getNomLivre());
    values.put(Key_photo,bibliothèque.geturiimage().toString());
    db.insert("Biblio",null,values);
    db.close();

}

and this is my variables:

    private static final String TABLE_Nom = "Biblio";
    private static final String KEY_ID = "id";
    private static final String KEY_Auteur = "Auteur";
    private static final String KEY_Livre = "Livre";
    private static final String Key_photo="Image";

the problem I don't know why but db.insert invert beetween Image and Livre and because of that I have an exception and I don't know why the value that I insert are ? ? ? in debug I can see that the value are correct ! . normaly the true expression must be :

INSERT INTO Biblio(Auteur,Livre,Image) VALUES (cc,test,(uri of picture))

this is the entire exception :

2927-2927/com.example.myapplication4.app E/SQLiteLog﹕ (1) table Biblio has no column named Livre
05-15 02:53:54.436    2927-2927/com.example.myapplication4.app E/SQLiteDatabase﹕ Error inserting Auteur=gsopfkgop Image=content://media/external/images/media/10 Livre=fhoksgkp
    android.database.sqlite.SQLiteException: table Biblio has no column named Livre (code 1): , while compiling: INSERT INTO Biblio(Auteur,Image,Livre) VALUES (?,?,?)
Was it helpful?

Solution

USE This Query to Create Table.

 db.execSQL
    ("CREATE TABLE Biblio (id INTEGER PRIMARY KEY AUTOINCREMENT ,Auteur TEXT,Livre TEXT,Image TEXT)");

then You have to insert record using Below code:

public void AddBook(Bibliothèque bibliothèque)
{
    SQLiteDatabase db=this.getWritableDatabase();
    //this.open();
    ContentValues values=new ContentValues();
    values.put(Auteur,bibliothèque.getNomAuteur());
    values.put(Livre,bibliothèque.getNomLivre());
    values.put(Image,bibliothèque.geturiimage().toString());
    db.insert("Biblio",null,values);
    db.close();

}

I hope its useful to you..

OTHER TIPS

2927-2927/com.example.myapplication4.app E/SQLiteLog﹕ (1) table Biblio has no column named Livre

Your table doesn't have a column named Livre, either you have a spelling mistake here, in your table creation code, or you haven't defined a column named Livre.

You should try to reinstall your app? Also, if your db schema has been changed after your app installed in your test device, you have to increase db version parameter to invoke onUpdate() method or reinstall your app to invoke onCreate().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top