JavaRanch » Java Forums »
Java »
Java in General
| Author |
.jar file not working
|
Adam Burda
Ranch Hand
Joined: Jul 19, 2011
Posts: 40
|
|
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.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
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
Joined: Jul 19, 2011
Posts: 40
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
And how are you adding the connector to JDBC to your classpath?
|
 |
Adam Burda
Ranch Hand
Joined: Jul 19, 2011
Posts: 40
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
To repeat: how are you adding that connector to your classpath?
|
 |
Adam Burda
Ranch Hand
Joined: Jul 19, 2011
Posts: 40
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
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
Joined: Jul 19, 2011
Posts: 40
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
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.
|
 |
 |
|
|
subject: .jar file not working
|
|
|
|