dimanche 29 novembre 2015

Jar bundled with JDBC-Sqlite and Sqlite-DB wont connect

I have run into a very peculiar problem with generating a Jar that uses JDBC and has a bundled database. This is actually for a college course and is a redundant and elementary exercise that I have absolutely no trouble grasping. The problem is, the professor wants us to give them a .jar file that contains the source code and the database.

I use IntelliJ and I know how to use external libraries and generate a .Jar (artifact in IntelliJ). IntelliJ generated Jars give a 'Could not connect to databse' error when run from windows command line.

I tried messing with class path and libraries in the IDE, but that did not help. I also made sure to point the connection string to a known working DB which also did not work.

I am not sure if this professor even knows whether or not a bundled database can run from inside a jar, and since they only use BlueJ ( a simple learning tool), I was wondering if perhaps a bundled DB will never run from a jar where the connection string does not specify a previously determined path.

Here is where it gets REALLY hairy. I went back to BlueJ in order to see if maybe I was making mistakes with the overly complicated IntelliJ. When I generate a Jar from BlueJ, it creates the jar, the IDE locks up, and when it finally terminates, it generates the sqlite library that I am using in my package. Upon double-clicking the BlueJ .jar, it generates a 0.0 KB database with the same name as the one that is bundled inside the JAR.

The assignment directions said to give the teacher a jar with the source code and database inside. It never implied that the teacher expects to run it from command line. This person is a phd in math and computer science and there is a chance that they are a bit noob when it comes to SWENG and that bundling these things in the jar is not tested/working with the SQLite JDBC library.

can anyone lend a hand? Each IDE generated jars with different problems and levels of insanity. The BlueJ problems in particular were very insane.

Anyone got a clue about this? Bottom line: Both jar have proper libraries and DB file bundled. BlueJ generated JAR has weird errors but displays my text menu and then claims that the database does not contain tables. IntelliJ generated jar gives what appears to be standard JVM error : "could not connect to DB" and displays NONE of my menu or logic unlike Bluej.

Both IDE/project using 1.8 java 8.

        Class.forName("org.sqlite.JDBC");
        conn = DriverManager.getConnection("jdbc:sqlite:test.db");
        System.out.println("Opened database successfully");

Aucun commentaire:

Enregistrer un commentaire