简体   繁体   中英

Get SQLite user version via JDBC connection

I'm using JDBC to connect to a SQLite database:

Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:/test.db");

Now my problem is that I'm not able to get the user version. I know that I can use PRAGMA but if I execute:

Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("PRAGMA user_version;");

then the retrieved result set will be closed (no data sets found).

Seems like you have problem in code not described in question because this snippet can set and get user_version without problem:

import java.sql.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Class.forName("org.sqlite.JDBC");
        Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");

        try(Statement statement = conn.createStatement()) {
            statement.execute("PRAGMA user_version = 10;");
        }

        try(Statement statement = conn.createStatement()) {
            try(ResultSet rs = statement.executeQuery("PRAGMA user_version;")) {
                System.out.println(rs.getInt(1));
            }
        }
    }
}

Sqlite adapter:

<dependency>
    <groupId>org.xerial</groupId>
    <artifactId>sqlite-jdbc</artifactId>
    <version>3.15.1</version>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM