• 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

JDBC not included into jar file?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there, was wondering if anyone could help me.

I developed an application which works with MySQL using JDBC. It all works fine, but when I try to create a JAR file for my program, the code that uses mySQL seems not to be included into the jar file!

I added code for displaying messages in different parts of my code to find out at what point the problem is. It looks like the code that goes after line "Statement statement = connection.createStatement();" does not get included into the jar file.

Here is my main class code:


import java.sql.*;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ResourceManagementApplication extends JFrame {
private static MainFrame mainFrame;

public static void main(String[] args) {
Database db = new Database();

try {
JOptionPane.showMessageDialog(null, "here 1",
"There was an error!", JOptionPane.ERROR_MESSAGE);

Connection connection = db.connect("jdbc:mysql://localhost:3306/", "root", "pw");

JOptionPane.showMessageDialog(null, "here 2",
"There was an error!", JOptionPane.ERROR_MESSAGE);

Statement statement = connection.createStatement();

JOptionPane.showMessageDialog(null, "here 3",
"There was an error!", JOptionPane.ERROR_MESSAGE);

statement.executeUpdate("USE ResourceManagementApplication;");
JOptionPane.showMessageDialog(null, "here 4",
"There was an error!", JOptionPane.ERROR_MESSAGE);

statement.close();
mainFrame = new MainFrame(connection);
}
catch( SQLException e ) {
e.printStackTrace();
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
If I create and run the jar file, I get error message saying "here 1" and "here 2", but nothing at all happens after that.

Any ideas why that could be? I really need to get this working!

Someone suggested that I need to include the JDBC driver into jar file. I have no idea how to do this - could someone help me with this (if this is, indeed, the solution)?
 
Ranch Hand
Posts: 122
Mac IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably just need to make sure that the jar file with the JDBC driver is in the classpath.
 
Olya Smith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[quote=Lucas Mireles]You probably just need to make sure that the jar file with the JDBC driver is in the classpath.[/quote]

Thanks for your reply. This sounds good. Do you mean just adding line 'Class-Path: mysql-connector-java-5.1.14-bin.jar' into manifest file? I just did that, it seemed to be working on my laptop, but won't work on another computer... am I missing something else?
 
Jesus Mireles
Ranch Hand
Posts: 122
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically I dont know how you are starting up your application or how your distributing the application across computers and without really knowing your situation its hard to give you a "best practice" recommendation.

Just off the top of my head i would imagine that you can probably simply unjar the driver jar and copy all the directories over to your jar file if you are distributing a single jar. If you have an IDE like Eclipse or IDEA then I believe you can export your application with the export wizard.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you missed understanding the fact that the line you added to the manifest file means that the JDBC driver jar will be in the same directory as the executable jar, and failed to ensure that was the case on that other computer.
 
Olya Smith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Perhaps you missed understanding the fact that the line you added to the manifest file means that the JDBC driver jar will be in the same directory as the executable jar, and failed to ensure that was the case on that other computer.



I did actually added it in and it sorted the original problem. The problem witht he second computer was that the driver was not installed in the program files/java folder.

Thanks anyone for help - it's working now!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use netbeans to include jar file in netbeans and it works
hope this might help
http://ferdidolot.wordpress.com/2009/06/14/java-mysql-jdbc-tutorial-using-netbeans-part-1/

thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic