aspose file tools*
The moose likes JDBC and the fly likes SQLite and connecting with Java Swing Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLite and connecting with Java Swing Application" Watch "SQLite and connecting with Java Swing Application" New topic
Author

SQLite and connecting with Java Swing Application

Joe Mastro
Greenhorn

Joined: Jan 05, 2012
Posts: 14
Ultimately, I am looking for the steps that I need to take to make sure my swing application communicates with a sqlite db even though they may exist in different directories. I am trying to run my swing application by executing a jar outside the IDE and be able to access a sqlite db.

Specifics:
I currently have a java swing application that connects to sqlite db through JDeveloper IDE 11.1.1.4.0. The db resides in the following directory: C:\sqlite\Java_Wrapper\sample.s3db. I can access and update data in the db without a problem as I have added the sqlitejdbc-v056.jar (located:C:\sqlite\Java_Wrapper\sqlitejdbc-v056.jar) to the library class path. However, when I deploy my project files to a Jar file, execute it, a make a call to the db it I get a java.lang.ClassnotFoundExceptionrg.sqlite.JDBC. When I open up the deployed jar file I see no indication that that the sqlite driver jar file was deployed with it. Any direction is appreciated....thanks.
Patryk Sosinski
Greenhorn

Joined: Sep 10, 2011
Posts: 18
As far as i remember You cannot embed external jars inside output jar. The solution to this are:
1. include required jars when starting application like: java -jar app.jar -cp libs/*.* (where in lib folder are all external jars)
2. Use some application to merge the compiled classess inside jars into one jar, for example http://one-jar.sourceforge.net/

Joe Mastro
Greenhorn

Joined: Jan 05, 2012
Posts: 14
Thanks. So using choice #1 in your reply would I add code to my main startup class to reference the external library or would I create a batch script to fire
off my application with java -jar app.jar -cp libs/*.* ?


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18665
    
    8

To allow your code to access classes in jars, you set the classpath. You can't do that in Java code, it's configuration that you have to do before running the code. So yes, a batch script would be one good way to do that configuration. Only not the way you posted there, though. Fortunately there are plenty of good tutorials online which explain how to set your classpath.
Joe Mastro
Greenhorn

Joined: Jan 05, 2012
Posts: 14
Got it. It seems like I need to do a little research on setting class paths. I'll see if i can get the batch file working although it does seem a little bit messy especially when I might need to distribute to users accross a network (I know...I know....sqlite is probably not the best dbms to use for this but it will only be for a few users. Thanks for the help.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

While I'm not going to answer your question but have you considered using Java DB that is already included in Java Platform?
Joe Mastro
Greenhorn

Joined: Jan 05, 2012
Posts: 14
No I have not. When I was looking for an embedded database the first thing that I came across was sqlite. I started using it along with some of the GUI interfaces out there for it and I found it easy and fun to use. I'll give Java Db a look....thanks.
Joe Mastro
Greenhorn

Joined: Jan 05, 2012
Posts: 14
I finally got it to work (not exactly how I want it to) but hopefully this helps someone:

Wherever your deploy folder is that contains your project jar file that you run, change file to zip.
Edit the manifest file to include a Class Path reference to the sqlite jar file, sqlitejdbc-v056.jar (in my case).
I put my sqlite jar file in the same directory as my project jar file in the Deploy folder.

Here is my manifest:



Keep in mind that this is a manual process as I could not figure out how to create the manifest WITH Class-Path: sqlitejdbc-v056.jar as part of the deployment profile in JDeveloper. I could create it with the Main-Class but not the Class-Path entry.
So, everytime you deploy you will need to change the manifest file again. If I figure out how to do it within JDev I'll post back.
Thanks everyone.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQLite and connecting with Java Swing Application