SQLite and JDBC: returns UnsatisfiedLinkError

2019-05-10 22:00发布

问题:

I am running Xubuntu in VirtualBox. I installed sqlite3 which for some reason does not come bundled any more. I added sqlite-jdbc-3.8.7.jar to my build path and run this simple code to test it.

import java.sql.*;
public class JDBC_test {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("org.sqlite.JDBC");  
        Connection connection = DriverManager.getConnection("jdbc:sqlite:test.db");
        connection.close();
    }
}

I get this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open(Ljava/lang/String;I)V
    at org.sqlite.core.NativeDB._open(Native Method)
    at org.sqlite.core.DB.open(DB.java:161)
    at org.sqlite.core.CoreConnection.open(CoreConnection.java:145)
    at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:66)
    at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:21)
    at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:23)
    at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45)
    at org.sqlite.JDBC.createConnection(JDBC.java:114)
    at org.sqlite.JDBC.connect(JDBC.java:88)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:233)
    at JDBC_test.main(JDBC_test.java:7)

I get the same error when I try to connect to an existing DB by substituting "test.db" with the full path to the file. Any ideas why?

回答1:

There is a bug in driver version 3.8.7 in xerial's bug tracker. The quick (and working) solution is to use driver version 3.8.6 until that bug will be fixed.

Update: the bug was fixed since version 3.8.10.2 (see new bug tracker on Github), I confirm that it works now.



回答2:

Version 3.8.11.2 works on Ubuntu 14 (I tested it on x86), it can be downloaded from: https://bitbucket.org/xerial/sqlite-jdbc/downloads



标签: java jdbc sqlite