0

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) stackState= (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.

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, Currenty, the code that i showed is into a class that extends SQLiteOpenHelper. Thanks. Regards. Jose.
SQLiteOpenHelper subclasses should look absolutely nothing like what you have posted. For example, you don't open your own databases in SQLiteOpenHelper -- SQLiteDatabase objects are provided to you as parameters to onCreate() and onUpgrade().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.