开发者

DatabasePathException with sqlite

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 )" );
        s开发者_Go百科t.prepare();
        st.execute();
        st.close();
        distillDB.close();
    }
    catch ( Exception e )
    {           
        e.printStackTrace();
    }


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)");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜