Results 1 to 3 of 3
  1. #1
    Godsent is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default creating .jar with jdbc driver?

    Ok, i made swing GUI that works just fine and connects to SQL, and then i made it into .jar using this line:

    Java Code:
    "C:\Program Files\Java\jdk1.6.0_06\bin\jar.exe" cfm MyJar.jar Manifest.txt blist/
    So all files that is in blist folder will be in jar file, and they are. Everything seems to work, except connecting to SQL.

    Connecting looks like this:
    Java Code:
    	public void createConnection() {
    		try {
    			setParameters(0, "step 1...");
    			String serverName = "127.0.0.1";
    			String mydatabase = "blist"; 
    			String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
    			setParameters(40, "step 2...");
    			Class.forName("com.mysql.jdbc.Driver").newInstance();
    			setParameters(60, "step 3...");
    			con = DriverManager.getConnection(url, "root", "");
    			stmt = con.createStatement();
    			setParameters(80, "step 4...");
    			connected = true;
    			setParameters(100, "step 5!");
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    I use setParameters void to set custom text for jLabel to find out where my application stops. And its step 2.

    So the problem must be with
    Java Code:
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Maybe i put it in .jar wrong, maybe i need specific line if using these jdbc?
    Please help

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    It sounds like your app can not find your driver... I compile all of my apps with netBeans and netBeans automatically creates a directory called "lib" and puts my driver in it... So you might want to try something like that...
    Who Cares... As Long As It Works...

  3. #3
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    either copy the files from the driver's jar into yours, or add it to the classpath when you run the application
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. DB2 JDBC Driver upgrade
    By sanssan in forum JDBC
    Replies: 2
    Last Post: 09-23-2008, 05:52 PM
  2. Jdbc Driver For Oracle
    By Swamipsn in forum New To Java
    Replies: 0
    Last Post: 08-14-2007, 05:31 AM
  3. JDBC Driver problem
    By Swamipsn in forum New To Java
    Replies: 3
    Last Post: 08-09-2007, 04:55 PM
  4. Help with JDBC driver
    By Daniel in forum JDBC
    Replies: 2
    Last Post: 07-03-2007, 09:16 PM

Posting Permissions

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