简体   繁体   中英

Sqlite database ..java.lang.ClassNotFoundException:org.sqlite.jdbc

Hello guys I have create a small java application for desktop that simple logs data into an sqllite database. The jar files work well on the computer that was built, but, when I distributed on other pc it display the message that goes like this java.lang.ClassNotFoundException:org.sqlite.jdbc I used this code: I know I have to change the classpath apparently, but I am not sure how to proceed so that this program work on other pcs. I notice that this programs works well on the pc that it was built on but it is because i used this classpath..."jdbc:sqlite:C:\\Users\\USUARIO\\Documents\\workspace\\School2015.sqlite"... which is my local computer.

My question is how do I change this classpath so that the program runs fine on other pc than the one it was built on?

public class sqlConnection {

    Connection conn=null;

    public static Connection dbConnector()
    {
        try{
            Class.forName("org.sqlite.JDBC");
            Connection conn=DriverManager.getConnection("jdbc:sqlite:C:\\Users\\USUARIO\\Documents\\workspace\\School2015.sqlite");
            JOptionPane.showMessageDialog(null, "BIENVENIDO! Estás Conectado");
            return conn;
           }catch (Exception e)
           {
            JOptionPane.showMessageDialog(null, e);
            return null;
           }

    }
}

Not sure how you package and/or run this but if you place the School2015.sqlite file inside of the built JAR file you are creating and reference it from the relative path instead of the absolute one you will have no problems sharing the app.

You could look into using Maven as a build tool that will allow you to package everything up.

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