title: Use existing database - Android Development
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1951805/how-to-access-an-existing-sqlite-database-in-android">How to access an existing sqlite database in Android?</a>  </p>
  </blockquote>
  
  
  
  <p>I've been searching for a long time but I can't find the answer. I want to copy my existing Sqlite database test.db with data in it in my application. So when the users download my app from the application the db is delivered with it.</p>
  
  <p>Now I'v seen a lot of references to the tutorials <a href="http://davehiren.blogspot.com/search?q=use+existing+sqlite+database" rel="nofollow noreferrer">this</a> and <a href="http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/" rel="nofollow noreferrer">this</a>. But none of them work for me.</p>
  
  <pre><code>    public class DatabaseAdapter extends SQLiteOpenHelper {
           private static String dbPath= "data/data/test.test.test/databases/"; 
           private static String dbName = "test"; 
           private SQLiteDatabase applicationDatabase;  
           private final Context applicationContext;
  
  
           public DatabaseAdapter(Context context) {    
                   super(context,  dbName , null, 3);
                   this. applicationContext  = context;
           }
  
  
           public boolean checkDataBase(){  
                   File dbFile = new File( dbPath +  dbName);  
     return dbFile.exists();
     }
  
  
            public void copyDataBase() throws IOException{  
     try {
  
                      InputStream input =  applicationContext .getAssets().open(dbName);
                             String outPutFileName=  dbPath  +  dbName ;
                        OutputStream output = new FileOutputStream( outPutFileName); 
                         byte[] buffer = new byte[1024];
                      int length;
                      while ((length = input.read(buffer))&gt;0){
                      output.write(buffer, 0, length);
                      }
                      output.flush();
                      output.close();
                      input.close();
           }
                         catch (IOException e) {
                       Log.v("error",e.toString());
                      }
       }
  
  
               public void openDataBase() throws SQLException{
                   String fullDbPath= dbPath + dbName;
                 applicationDatabase = SQLiteDatabase.openDatabase( fullDbPath,     null,SQLiteDatabase.OPEN_READONLY);
       }
  
                  @Override
    public synchronized void close() {
            if( applicationDatabase != null)
              applicationDatabase .close();
                 super.close();
    }
  @Override
  public void onCreate(SQLiteDatabase arg0) {
      // TODO Auto-generated method stub
  
  }
  
  
  @Override
  public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
      // TODO Auto-generated method stub
  
  }
  
  public void getit(){
      this.getReadableDatabase().rawQuery("SELECT * FROM test", null);
  }
  
  
  
  
  
  
  }
  </code></pre>
  
  <p>I get the error code = 1 no such table.
  If I check the database is created but only with the table android_metadata.</p>
  
  <p>Someone a working example?</p>