You need to download an arm build of SQLite library. I found only one place where you can get it: https://bitbucket.org/xerial/sqlite-jdbc/issue/79/compile-for-arm
Error opening connection SQLite on Raspberry pi
-
22-07-2023 - |
質問
Update: I just check the latest JDBC jar which I use, and it's missing the map /Linux/arm/libsqlitejdbc.so, Would this problem be fixed by downloading this file from somewhere? Can't find it anywhere.
Edit: Problem seems to be this, however I don't know how to fix this.
Caused by: java.lang.Exception: Error loading native library: /org/sqlite/native/Linux/arm/libsqlitejdbc.so
I'm trying to use a SQLite database on my raspberry pi. However I can't get it to work. I get the output posted below. I'm using the JDBC driver. The code works fine on my main computer. I have searched everywhere but can't find a solution. I packed my code into a Jar file if that matters.
Relevant code:
private final String dbLocation = "jdbc:sqlite:" + System.getProperty("user.home") + "/ServerSQLite.db";
public SQLServer() throws ClassNotFoundException {
System.out.println("DB location: " + dbLocation);
Connection connection = null;
Class.forName("org.sqlite.JDBC");
try {
// create a database connection
connection = DriverManager.getConnection(dbLocation);
Output:
DB location: jdbc:sqlite:/usr/share/tomcat7/ServerSQLite.db
Error opening connection
Edit: same problem with hardcoded location which should have both read and write permission:
jdbc:sqlite:/home/pi/ServerSQLite.db
Error opening connection
Thankful for any help I can get :)
Edit 2: Thought I printed stack trace, but didn't here it is:
java.sql.SQLException: Error opening connection
...Lots of exception
Caused by: java.lang.Exception: Error loading native library: /org/sqlite/native/Linux/arm/libsqlitejdbc.so
at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:241)
...
at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:175)
... 29 more
Error opening connection
Problem seems to be Caused by:
java.lang.Exception: Error loading native library: /org/sqlite/native/Linux/arm/libsqlitejdbc.so
解決
他のヒント
For some reason, it looks like the Pi's $HOME
is set to a read-only system location. This is buggy, but the best workaround is to permit the user to specify a property that will override the entire file name instead of always using the home directory.
I use this in my POM and works fine for me
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.8.10.1</version>
</dependency>
If you only need the jar
Running on: ldd (Debian GLIBC 2.19-18+deb8u4) 2.19 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.