# How to use SQLite without GUI? only print console

**URL:** <https://discuss.kotlinlang.org/t/how-to-use-sqlite-without-gui-only-print-console/30803>\
**Category:** Uncategorized\
**Created:** [October 24, 2025, 11:40pm UTC](https://discuss.kotlinlang.org/t/how-to-use-sqlite-without-gui-only-print-console/30803 "2025-10-24T23:40:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmercadolibretuc](https://avatars.discourse-cdn.com/v4/letter/v/5fc32e/32.png) [@vmercadolibretuc](https://discuss.kotlinlang.org/u/vmercadolibretuc)\
**Post date:** [October 24, 2025, 11:40pm UTC](https://discuss.kotlinlang.org/t/how-to-use-sqlite-without-gui-only-print-console/30803/1 "2025-10-24T23:40:08Z")

</div>

```auto
With the GUI, everything is fine, but when I try to do it without the GUI, I get errors.
Is this possible? I'm new to Kotlin. Thank you very much.

```

---

<div class="post-metadata">

**Author:** ![brunojcm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/brunojcm/32/5116_2.png) [@brunojcm](https://discuss.kotlinlang.org/u/brunojcm)\
**Post date:** [October 26, 2025, 10:54am UTC](https://discuss.kotlinlang.org/t/how-to-use-sqlite-without-gui-only-print-console/30803/2 "2025-10-26T10:54:24Z")

</div>

You probably need to post some code so people can help you.

---

<div class="post-metadata">

**Author:** ![vmercadolibretuc](https://avatars.discourse-cdn.com/v4/letter/v/5fc32e/32.png) [@vmercadolibretuc](https://discuss.kotlinlang.org/u/vmercadolibretuc)\
**Post date:** [October 26, 2025, 8:31pm UTC](https://discuss.kotlinlang.org/t/how-to-use-sqlite-without-gui-only-print-console/30803/3 "2025-10-26T20:31:13Z")

</div>

```auto
package com.example.sql_lite_dos
data class Rubro (val id:String, val detalle:String,val inc:Float)

package com.example.sql_lite_dos

import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper

//class dbOpenHelper (context:Context): SQLiteOpenHelper
// (context,DATABASE_NAME,null,DATABASE_VERSION){

class dbOpenHelper (context:Context): SQLiteOpenHelper
    (context,DATABASE_NAME,null,DATABASE_VERSION){

    override fun onCreate(p0: SQLiteDatabase?) {
        TODO("Not yet implemented")
    }

    override fun onUpgrade(
        p0: SQLiteDatabase?,
        p1: Int,
        p2: Int
    ) {
        TODO("Not yet implemented")
    }

    companion object {
        private const val DATABASE_NAME="database.db"
        private const val DATABASE_VERSION=3
        private const val TABLE_NAME="rubros"
        private const val COLUMN_ID="id"
        private const val COLUMN_DETALLE="detalle"
        private const val COLUMN_INC="inc"
    }
    fun insertRubros(rubro:Rubro) {
        val db=this.writableDatabase

        val values= ContentValues().apply {
            put(COLUMN_ID,rubro.id)
            put(COLUMN_DETALLE,rubro.detalle)
            put(COLUMN_INC, rubro.inc)
        }
        db.insert(TABLE_NAME,null,values)
        db.close()
            }

}

/// i can't insert record here (error declare lateinit)

package com.example.sql_lite_dos
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import com.example.sql_lite_dos.dbOpenHelper

fun main(){
    lateinit var db:dbOpenHelper

    val registro=Rubro("ASX","ASCII TABLE",3.25f)
    //db= dbOpenHelper(this)

    db.insertRubros(registro)

}

```

Sorry i forgot, 3 files

---

<div class="post-metadata">

**Author:** ![zhengkeli](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/zhengkeli/32/3974_2.png) [@zhengkeli](https://discuss.kotlinlang.org/u/zhengkeli)\
**Post date:** [October 27, 2025, 1:03am UTC](https://discuss.kotlinlang.org/t/how-to-use-sqlite-without-gui-only-print-console/30803/4 "2025-10-27T01:03:38Z")

</div>

You can take a look at [Exposed](https://www.jetbrains.com/exposed/) if you are already familiar with SQL things.

---

<div class="post-metadata">

**Author:** ![Skater901](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/skater901/32/10163_2.png) [@Skater901](https://discuss.kotlinlang.org/u/Skater901)\
**Post date:** [October 28, 2025, 12:43pm UTC](https://discuss.kotlinlang.org/t/how-to-use-sqlite-without-gui-only-print-console/30803/5 "2025-10-28T12:43:06Z")

</div>

I mean looking at your code, it looks pretty obvious? You’ve declared a variable called `db`, but never assigned a value to it. You then try to use `db`, but it doesn’t have a value. Change `db` from `lateinit var` to `val`, and the compiler will tell you the problem.
