开发者

Creating database in android

i was creating a database and deleting it, adding registries on my android htc mobile sqlite database without any problem.

But now, after last deleting of the database everytime i want to create a new one i get a sqlite exception that says me "unable to open database file" with the following data:

serialVersionUID (RuntimeException)= -7034897190745766939

cause= SQLiteException (id=830058513528)

cause= SQLiteException (id=830058513528)

detailMessage= "unable to open database file" (id=830058513560) stackSt开发者_JS百科ate= (id=830058513672)

stackTrace= null

This is my code to create a database:

private static String DB_PATH = "/data/data/Android.Applications/databases/testdatabase.db";

public void OpenDataBase(){

            SQLiteDatabase ApplicationDB = null;
            //Si existe la base de datos
            if(checkDataBase())
            {
                //Open readonlymode
                String myPath = DB_PATH;
                //open database as readwrite mode
                ApplicationDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
            }
            else
            {
                try
                {
                    String myPath = DB_PATH ;
                    ApplicationDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.CREATE_IF_NECESSARY);
                    CreateTables();
                    //create all the necessary tables
                    System.out.println("DataBASE CREATED");
                }
                catch(SQLiteException e)
                {
                    System.out.println("SQL LiteException"+ e.getMessage());
                }
            }
        }

 private boolean checkDataBase(){

        try{
            String myPath = DB_PATH;
            ApplicationDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

        }catch(SQLiteException e){

            //database does't exist yet.
        }
        if(ApplicationDB != null){

            ApplicationDB.close();
        }
        return ApplicationDB != null ? true : false;
    }

And this is the code for delete database

 public boolean DeleteDatabase()
        {
            boolean wasdeleted;
            try
            {
                File file=new File(DB_PATH);
                wasdeleted=file.delete();
            }
            catch(SecurityException e)
            {
                wasdeleted=false;

            }
            return wasdeleted;
        }

Could you give me a hand? im stucked here, cause this code works few hours ago...

Thanks in advance. Best Regards. Jose.


You might consider switching to use SQLiteOpenHelper, which would eliminate most of your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜