Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

.jar file not working

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need some help and hope I am in the right place.

I made a Java database app in a GUI. The app runs fine with no errors, and does what I want it to do. When I make the app into a .jar the app starts up but does not input data into the MySQL table. Here is the code.
I even took out the System.out.println(); and tryed again with making the .jar file still does not work.

 
Marshal
Posts: 74360
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read this. You appear to have posted lots of code with long lines in, so people can’t read it, but chances are none of that code is relevant to the question.
Please show us how you are trying to create the .jar, and the complete contents of the manifest file.
 
Adam Burda
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok,
Sorry that the code was so long here is the SQL part of the code. It is with in the ButtonListener method of the class.



As for making the .jar file what I did was,
1. Made a MyManifest.txt file and in that i wrote Main-Class: Contact then pressed enter twice saved the file named MyManifest. Contact is the main class of my app.
2. in CMD i wrote jar cfm JarFileName.jar MyManifest.txt Contact.class ContactFrame.class ContactP$1.class ContactP$ButtonListener.class ContactP.class

The jar file works, the app runs. But as for sending data to the SQL table that does not work.
It only sends data to the SQL table if I run the app in CMD.
 
Campbell Ritchie
Marshal
Posts: 74360
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And how are you adding the connector to JDBC to your classpath?
 
Adam Burda
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I downloaded a driver from mysql.com/products/connector, unziped it, added the drivers .jar file to the class path variable. c:\mysql\mysql-connector-java-5.0.4-bin.jar
in the class file i have

import java.sql*.;

and in the ButtonLinstener method i have

System.out.println("Inserting values in Mysql database table!");
Connection con = null;
String url = "jdbc:mysql://localhost/ContactList";
String user = "root";
String pw = "marty95";
String driver = "com.mysql.jdbc.Driver";
 
Campbell Ritchie
Marshal
Posts: 74360
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To repeat: how are you adding that connector to your classpath?
 
Adam Burda
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure what you are asking.

added the drivers .jar file to the class path variable. c:\mysql\mysql-connector-java-5.0.4-bin.jar
 
Campbell Ritchie
Marshal
Posts: 74360
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you use the -cp option when you started the jar file, or is the classpath in the manifest file? I think it is better in the manifest file. If you don’t supply a classpath, the app can’t find the jar with the connector in.
 
Adam Burda
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok im a little lost here? What do you mean -cp? As for the Manifest.txt file, I opened note pad inside that I wrote

Main-Class: Contact

Saved that as MyManifest.txt to the folder where the app files are.

Contatc is the main of the app.
the files are
Contact.java
ContactFrame.java
ContactP.java

The class files are.
Contact.class
ContactFrame.class
ContactP$1.class
ContactP$ButtonListener.class
ContactP.class

Then in CMD I wrote

jar cfm JarFileName.jar MyManifest.txt Contact.class ContactFrame.class ContactP$1.class ContactP$Buttonlistener.class ContactP.class
 
Campbell Ritchie
Marshal
Posts: 74360
334
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to supply a classpath which includes the location of the connector classes. If you go through the Java tutorials section, you find it in the section about adding other classes to the classpath.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic