title: Connecting to existing database in Kotlin
body: <p>I try to use precreated database for my android app written in Kotlin, so in my databaseHelper class I tried to use the following code for that:</p>
  
  <pre class="lang-kotlin prettyprint-override"><code>    override fun onCreate(db: SQLiteDatabase)
      {
          db = SQLiteDatabase.openDatabase(DATABASE_PATH + DATABASE_NAME,null,SQLiteDatabase.OPEN_READWRITE)
  
      }
  </code></pre>
  
  <p>I thought this will worm, but I get the message <code>val cannot be reassigned</code>.</p>
  
  <p>Then in the next methods, which are supposed to perform actions on database (execute all needed queries) I reffer to the database like that: </p>
  
  <pre class="lang-kotlin prettyprint-override"><code>        val db = this.writableDatabase
          val cursor = db.rawQuery(query, null)
  </code></pre>
  
  <p>(or just with <code>db.execSQL(query)</code> if don't need the results of selection; of course <code>query</code> is a string with SQL query)</p>
  
  <p>The point is how can I access the precreated database because when I would just create new "global" variable (in companion object?) then I would have to reffer to it in diffent way... at least I think so... well maybe using the line <code>val db = this.writableDatabase</code> also in onCreate would do, but wouldn't it connect just "localy"(as I overrwrite the refference for db in parameter by local variable) instead of putting this precreated database into what is returned by <code>this.writableDatabase</code>?</p>
  
  <p>Edit:
  Well I think I find a solution to how to connect to database here <a href="https://discuss.kotlinlang.org/t/how-to-use-pre-populated-sqlite-database-using-kotlin/8068" rel="nofollow noreferrer">https://discuss.kotlinlang.org/t/how-to-use-pre-populated-sqlite-database-using-kotlin/8068</a> but it still leave me with one serious problem: how to include that database in AndroidStudio project (to have something to connect to).
  I mean that include this database as part of an app (as one of its resources)</p>