Results 1 to 18 of 18
  1. #1
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default JAR files+ MySQL

    I have made an simple application in which I have used MySQL to store data. When run the code in netbeansIDE,it works well.

    But when I click double on the jar file,it cant access the MySQL.

    How can I solve this?

    Thanks in advanced
    Last edited by UJJAL DHAR; 03-06-2011 at 05:40 PM. Reason: SOLVED

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    I have made an simple application in which I have used MySQL to store data. When run the code in netbeansIDE,it works well.

    But when I click double on the jar file,it cant access the MySQL.

    How can I solve this?

    Thanks in advanced
    You jar file should have a manifest entry that manages the MySQL jar file in its classpath line; read the documentation.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    I have read the documentation. I have failed to get the main point.
    Please help me a bit more.

    I am using Netbeans IDE 6.8 and mysql-connector-java-5.0.8-bin.jar
    What should I do now?


    Please help me.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    I have read the documentation. I have failed to get the main point.
    Please help me a bit more.

    I am using Netbeans IDE 6.8 and mysql-connector-java-5.0.8-bin.jar
    What should I do now?


    Please help me.
    Are you sure you've read the documentation? It's all in there; oh well, put the following lines in your manifest entry:

    Java Code:
    Main-Class: <your main class>
    Class-Path: <path to>/mysql-connector-java-5.0.8-bin.jar
    Oh, and b.t.w. Netbeans has nothing to do with this; also make sure that you put the actual values for the < ... > placeholders above.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    My manifest file is aaa.mf

    Java Code:
    Main-Class: Main
    Class-Path: C:/Program Files/Java/jdk1.6.0_01/jre/lib/ext/mysql-connector-java-5.0.8-bin.jar
    Here my Main class is Main.java.
    Before adding Shop.jar is working without accessing database.

    Java Code:
    jar cvfm Shop.jar aaa.mf
    But after adding manifest
    it shows
    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: Main
    I think I am going too silly.please help me.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    Java Code:
    jar cvfm Shop.jar aaa.mf
    That command doesn't add any .class files to your .jar file; check it with, say, winzip because a .jar file is simply a .zip file.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    Oh, then what will be the commands ?
    Do you have any link or anything?

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    Oh, then what will be the commands ?
    Do you have any link or anything?
    I already gave you a link to the documentation for the jar command; haven't you read it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    this time I have executed
    [code]
    jar uf Shop.jar mysql-connector-java-5.0.8-bin.jar
    [code]

    And there was no error executing this.But still database is not accessible. Should I add more files.Then what they are?

    mysql-connector-java-5.0.8-bin.jar is JDBC connector which i have used to connect netbeans with MySQL.Is it okay to add?

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    this time I have executed
    Java Code:
    jar uf Shop.jar mysql-connector-java-5.0.8-bin.jar
    And there was no error executing this.But still database is not accessible. Should I add more files.Then what they are?

    mysql-connector-java-5.0.8-bin.jar is JDBC connector which i have used to connect netbeans with MySQL.Is it okay to add?
    Now you have added that MySQl jar file to your own jar file; the jar tool doesn't mind but adding jars to a jar never works; never. You are supposed to add your own .class file(s) to that jar like your Main.class file; don't just guess and add all sorts of files to your .jar file hoping that it would work.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    Now this is working if I run it with command promt writing

    java -jar Shop.jar



    but When clicking double database is not accessing.

    Java Code:
    In Filetypes
    JAR files are executing with
    "C:\Program Files\Java\jre1.6.0_01\bin\javaw.exe" -jar "%1" %*
    in my pc

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    Now this is working if I run it with command promt writing

    java -jar Shop.jar



    but When clicking double database is not accessing.

    Java Code:
    In Filetypes
    JAR files are executing with
    "C:\Program Files\Java\jre1.6.0_01\bin\javaw.exe" -jar "%1" %*
    in my pc
    Conclusion: your manifest entry is incorrect again; reread my first reply and the documentation I supplied.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    No..
    I just change this
    "C:\Program Files\Java\jre1.6.0_01\bin\javaw.exe" -jar "%1" %*

    to
    "C:\Program Files\Java\jdk1.6.0_01\bin\java.exe" -jar "%1" %*

    And its working.Thanks a lot.my problem is solved.

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    No..
    I just change this
    "C:\Program Files\Java\jre1.6.0_01\bin\javaw.exe" -jar "%1" %*

    to
    "C:\Program Files\Java\jdk1.6.0_01\bin\java.exe" -jar "%1" %*

    And its working.Thanks a lot.my problem is solved.
    Strange, because the only difference between those two lines is the display of a console window ...

    kind regards,

    Jos

    edit: or was that what your question was all about? Displaying the console ...
    Last edited by JosAH; 03-06-2011 at 06:05 PM.
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    No no....lets review...
    I have prepared a Restaurant management system using MySQL+Netbeans.A JAR file was created by which we can execute the system only with double click.But the jar file was not capable of accessing MySQL.
    My Question was how to make sure that jar file can access database?

    Your answer was to add the mysql connector to the jar.

    I have added it as your direction.But when I was running the JAR file using command prompt
    java -jar Shop.jar
    ,it works.

    But it didnt work with double click.
    Because of
    "C:\Program Files\Java\jre1.6.0_01\bin\javaw.exe" -jar "%1" %*
    Then I changed it to
    "C:\Program Files\Java\jdk1.6.0_01\bin\java.exe" -jar "%1" %*
    .and now its working

    Thats it.

  16. #16
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by UJJAL DHAR View Post
    No no....lets review...
    I have prepared a Restaurant management system using MySQL+Netbeans.A JAR file was created by which we can execute the system only with double click.But the jar file was not capable of accessing MySQL.
    My Question was how to make sure that jar file can access database?

    Your answer was to add the mysql connector to the jar.

    I have added it as your direction.But when I was running the JAR file using command prompt ,it works.

    But it didnt work with double click.
    Because of

    Then I changed it to .and now its working

    Thats it.
    I still don't understand that changing 'javaw' to 'java' makes it work but I'm happy for you that you have working software now.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #17
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    I m not sure also about the fact.
    I will search for the answer of a question in future but not today.

    What is the difference between javaw.exe of JRE and java.exe of JDK
    Thanks a lot JosAh for being with me.

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    I mentioned this on the other thread over in Databases where you were "helping" someone with a problem but:
    Class-Path: C:/Program Files/Java/jdk1.6.0_01/jre/lib/ext/mysql-connector-java-5.0.8-bin.jar

    You do not want to be putting anything in there.
    That's a mistake, and possibly why Netbeans hasn't done what it should, which is stick them mysql connector jar into your dist directory, and a proper entry into the Manifest.

    Fix that mistake, stick the jar file in a lib directory under your Netbeans project and reference it properly, and Netbeans will build you a nice jar file, with associated lib in a dist directory.

Similar Threads

  1. Replies: 8
    Last Post: 07-30-2010, 05:47 PM
  2. Storing video files in mysql database
    By mrvigneshmca in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2009, 03:50 PM
  3. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM
  4. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  5. how to convert mpeg files to .wav files
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:14 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
  •