Results 1 to 15 of 15
  1. #1
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default How to get Jar files to work with Databases

    Hey all,

    I made a cool little database program with the latest version of mysql connector j.

    When I compile it, it works great. But, when compress it into a .jar file (runnable program file), it doesn't work.

    There must be something I'm doing wrong. Do I need to put the mysql-connector .jar file somewhere?

    I know how to find my Manifest.MF file. But I don't know what to do with it. (I've heard there's something that I gotta do with that).

    Have I searched google? Yes, but none of it helps much. I think some direct help is needed.
    Last edited by hunterbdb; 12-30-2008 at 03:46 AM.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    You can either include everything from the MySQL JAR into your JAR, or you can include both JAR's in your classpath on the java command. Typically, the second choice is preferred.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Steve11235 View Post
    You can either include everything from the MySQL JAR into your JAR, or you can include both JAR's in your classpath on the java command. Typically, the second choice is preferred.
    Or simply place the mysql driver jarfile in the proper place (depends on how you do the next step) and configure the manifest file correctly, so you can simply execute java -jar yourfile.jar (or "double-click" as everyone seems to like to refer to it).

    Edit: Which the tutorial posted covers, of course.
    Last edited by masijade; 12-30-2008 at 07:04 PM.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    a booga wooga wooga woo!

    P.S. English only, please. And, since I seemingly don't have the font that is needed to display it, I don't even know what language it is you used. And "70000" what? As that (the first word of none title text) was the only thing that could be read, as an actual word/number, here.

  6. #6
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default

    okay, great, but the tutorial did not help at all. can somone simply tell me how to add a classpath to the jar? Where do I put the mysql .jar?
    look at my .jar file:


    Where does the mysql .jar file go?

  7. #7
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by Wigneezesee View Post
    70000 девственниц порно хентай порно бабушки колготки просмотр порно бесплатно целок
    ретро порно фото бабушек фото старых бесплатно скачать порно старые порно картинки старые трахнуть девственницу
    that was unhelpful.


    I don't speak booba-holla-backa-boobish.

  8. #8
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default

    I get this error when I try to run my .jar file:


  9. #9
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    There is an attribute called "Class-Path" that you can specify in the manifest of your jar. Add the mysql jar to this attribute and you should now have access to the classes contained in the mysql jar.

  10. #10
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by hunterbdb View Post
    okay, great, but the tutorial did not help at all. can somone simply tell me how to add a classpath to the jar?
    It didn't. Yes it does, you didn't bother to read it all.

    Check Working with Manifest Files: The Basics (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)

    Specifically Adding Classes to the JAR File's Classpath (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)

    Where do I put the mysql .jar?
    Any where you want to so long as it is referenced in the manifest file.
    Last edited by masijade; 01-01-2009 at 11:00 AM.

  11. #11
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    It didn't. Yes it does, you didn't bother to read it all.

    Check Working with Manifest Files: The Basics (The JavaЩ Tutorials > Deployment > Packaging Programs in JAR Files)

    Specifically Adding Classes to the JAR File's Classpath (The JavaЩ Tutorials > Deployment > Packaging Programs in JAR Files)



    Any where you want to so long as it is referenced in the manifest file.

    Yes, I did bother to read the tutorial. What I am asking is how to make my program distributable. I specified the classpath for mysql's .jar file, but that's not enough, is it? Because if I give my .jar file for my project to my friend and he tries to run it on his computer, then the classpath is invalid because the mysql connector jar will be non existent on his computer.

    So, how do I package everything so that I can let someone download a file and the program works on his computer?

    classpaths are paths to jar files on your computer, right? how then, do you make it so that the classpath is accurate on any computer. Do I need to put the mysql .jar file in the user's jre, and then somehow re-write the program's classpath for that location?

    People put the jre in different locations on their computer, so how does my program know the classpath to the mysq connector .jar for the computer it is downloaded onto?

    I'm sorry for not being clear on my question. thankyou for all the help so far.

  12. #12
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Package both the mysql jar and your jar into the same directory and reference the mysql jarfile using a relative path (as shown in the tutorial). The MySQL Driver jarfile is freely redistributable. So, what's the problem.

  13. #13
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I see what you are getting at. Been there, done that.

    You will have to create some sort of installer that places both your JAR and any other JAR's into a directory.

    I provided a batch (cmd) file that sets the classpath and executes the java command. I also found a hack EXE on the Internet that allowed me to create a shortcut for All Users (Windows installation) on the desktop.

    Bottom line, I don't know of any elegant way to do this. It may be possible to repackage the MySQL JAR into your JAR, but I think you will run into licensing issues at that point.

  14. #14
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    Arse-biscuits...just noticed the date on this!

    Oopsie.

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. struts 2 and databases
    By rantravee in forum Web Frameworks
    Replies: 1
    Last Post: 12-23-2008, 06:59 AM
  2. password username and databases
    By chalo in forum JCreator
    Replies: 0
    Last Post: 12-02-2008, 08:11 AM
  3. how to use XML databases
    By paty in forum XML
    Replies: 3
    Last Post: 08-16-2008, 12:11 AM
  4. Recommendation about databases
    By tommy in forum JDBC
    Replies: 2
    Last Post: 07-28-2007, 05:04 AM
  5. multiple databases
    By varunthecool in forum JDBC
    Replies: 2
    Last Post: 07-09-2007, 08:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •