views:

11

answers:

1

I created a sqlite database, but after creating the schema I am getting an exception in the following code:

    try
    {
        URI myURI = URI.create("file:///SDCard/Databases/dbstill.db");
        distillDB = DatabaseFactory.open(myURI);
        Statement st = distillDB.createStatement( "CREATE TABLE 'People' ( " +
            "'Name' TEXT, " +
            "'Age' INTEGER )" );
        st.prepare();
        st.execute();
        st.close();
        distillDB.close();
    }
    catch ( Exception e )
    {           
        e.printStackTrace();
    }
A: 

You should only create a table once. If you try to create it every time, you will get an exception because the table already exists.
I suggest using the "IF NOT EXISTS" feature from sqlite:

Statement st = distillDB.createStatement( 
    "CREATE TABLE IF NOT EXISTS 'People' ('Name' TEXT, 'Age' INTEGER)");
Michael Donohue