• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQLite and connecting with Java Swing Application

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.ClassnotFoundException:org.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.
 
Greenhorn
Posts: 19
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/*.* ?


 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic