简体   繁体   中英

No suitable driver found for jdbc:sqlite

I have problems getting connection to my SQLite database. On my Windows PC everything works fine, but if I want to run my program on Linux(Raspberry PI) I'm getting error as shown in title.

This is my connection on Windows:

public static final String DB_NAME = "settings.db";
public static final String CONNECTION_STRING = "jdbc:sqlite:C:\\Users\\oschr\\eclipse-workspace\\Dippmitteldosierer\\src\\" + DB_NAME;

Before I export my program for Linux I change my connection string:

public static final String CONNECTION_STRING = "jdbc:sqlite:/home/pi/Desktop/" + DB_NAME;

If there's no database I create it with this code:

String url = CONNECTION_STRING;
try {
    try {
        Class.forName("org.sqlite.JDBC");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    connection = DriverManager.getConnection(url);
    statement = connection.createStatement();
    
    statement.execute("CREATE TABLE IF NOT EXISTS " + TABLE_VORWAHLMENGEN + "( " + COLUMN_VORWAHLNAME + " TEXT, " + COLUMN_VORWAHLMENGE + " INTEGER)");
    statement.execute("CREATE TABLE IF NOT EXISTS " + TABLE_KALIBRIERUNGEN + "( " + COLUMN_KALIBRIERUNGNAME + " TEXT, " + COLUMN_KALIBRIERUNGMENGE + " INTEGER)");

This is my build path:
这是我的构建路径

This is my project:
这是我的项目

Can anybody help me please?

You are using some process that you didn't explain in your question to make a jar. You are then shipping this jar to the pi and running it there.

The process you are using is just turning your code into a jar. It is not including all your dependencies; this is not normally done, as it makes jars gigantic, and complicates updates.

Option 1: executable jars with classpath entries

You need to end up with a jar that has a Class-Path entry in the manifest that lists jdbc-sqlite.jar , and then ensure that this jar is available in the same directory as 'sibling' to yourapp.jar . How? Well, that depends on whatever process is turning your class files into jar files.

Option 2: Don't use java -jar to run it.

You can do the above by hand, if you run java -jar sqlite.jar:yourapp.jar com.foo.YourMainClass there.

Option 3: Striping

Update that process so that it stripes the dep(s) into a single gigantic everything jar. Generally, you need a build system such as maven or gradle to do this.

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