Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Failing to load from sqlite database with JDBC

    Hello,

    having recently gotten my hands on Stata 17, I wanted to try if it is possible to work with sqlite databases (basically, a db embedded in a single file) via the new JDBC functionality.

    Using the jar file from https://github.com/xerial/sqlite-jdbc, I am able to connect to a file, list tables, insert data, but loading data from a table fails with r(683) "failed to load resultset column".

    I was thus wondering if maybe somebody has an idea what the problem is, or has been able to use JDBC with sqlite.

    Example code (insert simulated data into temporary file and try to load them):

    Code:
    clear
    set obs 1000
    gen double x = rnormal()
    gen str1 y = cond(runiform()<0.5, "A", "B")
    
    // jar source: https://github.com/xerial/sqlite-jdbc/releases/download/3.36.0.3/sqlite-jdbc-3.36.0.3.jar
    local jar "sqlite-jdbc-3.36.0.3.jar"
    local driverc "org.sqlite.JDBC"
    tempfile tmpdb
    local url "jdbc:sqlite:`tmpdb'"
    local user "user"
    local pass "password"
    jdbc connect, jar("`jar'") driverclass("`driverc'") url("`url'") user("`user'") password("`pass'")
    
    jdbc exec "CREATE TABLE tbl1 (x REAL, y TEXT);"
    jdbc insert, table("tbl1")
    jdbc showtables
    jdbc describe "tbl1"
    
    clear
    jdbc load, table("tbl1")

  • #2
    Ivan,

    I believe I fixed a bug with NULL values and TEXT columns that with fix your issue.

    Comment


    • #3
      I had another user report this problem and it seems that some SQLite JDBC drivers have a bug. The SQLite driver I tested with, sqlite-jdbc-3.40.1.0.jar, has a bug for TEXT/String data. The Java API call

      Code:
       int columnSize = resultSetMetaData.getPrecision();
      is returning 0 when it should return the max length of the column. I will add code that if columnSize is 0, I will set the columnSize to a Stata strL.
      Last edited by Kevin Crow (StataCorp); 22 Feb 2023, 10:06.

      Comment


      • #4
        Thanks Kevin for the update.

        Actually the ODBC SQLite Driver is the way to go, if the SQLite3 database has a TEXT/String field, until Stata releases an upgrade to solve JDBC bug.

        Please, let us know as soon as you release that.

        thks.

        Comment

        Working...
        X