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)");
精彩评论