Results 1 to 17 of 17
  1. #1
    tarkowc is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default Problem loading JDBC SQL driver.

    My Java file compiles fine and runs fine with the "java resAssetts.class". But I am trying to create a Jar file. I successfully create the Jar file, but when I run it it says "java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerDataSource".

    My code is as follows:

    import java.lang.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import javax.sql.*;
    public class resAssetts extends Frame implements ActionListener, WindowListener
    {

    public static void main(String args[])
    {
    resAssetts reserveAssetts = new resAssetts();
    Connection con = null;
    try
    {
    // Setting up the DataSource object
    Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver"); com.microsoft.sqlserver.jdbc.SQLServerDataSource ds = new

    com.microsoft.sqlserver.jdbc.SQLServerDataSource() ;
    ds.setServerName("server");
    ds.setDatabaseName("db");
    ds.setInstanceName("subdirectory");
    ds.setUser("user");
    ds.setPassword("pass");

    // Getting a connection object
    con = ds.getConnection();

    // Getting database info
    DatabaseMetaData meta = con.getMetaData();
    // Closing the connection
    con.close();
    }
    catch (Exception e)
    {
    System.err.println(e.getMessage());
    }
    reserveAssetts.setSize(550,500);
    reserveAssetts.setVisible(true);
    }

    public resAssetts()
    {
    }

    public void paint(Graphics g)
    {

    }

    public void actionPerformed(ActionEvent e)
    {
    }

    public void windowClosing(WindowEvent event)
    {
    System.exit(0);
    }
    public void windowIconified(WindowEvent event){}
    public void windowOpened(WindowEvent event){}
    public void windowClosed(WindowEvent event){}
    public void windowDeiconified(WindowEvent event){}
    public void windowActivated(WindowEvent event){}
    public void windowDeactivated(WindowEvent event){}
    }

    I added the path to the sqljdbc.jar file to my classpath in Windows.

    What am I doing wrong?

  2. #2
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default

    maybe try to include your connector in the jar file. just an idea from a noob :D

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default

    Add the driver to your classpath. This is a very common issue...search the forums and you will find a large quantity of posts describing how to solve the issue.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default

    What IDE are you using (if any)?
    Essentially you need to end up with a deployment directory containing everything you need to run your code. In your case it would contain your jar file and (possibly in its own lib directory) the JDBC jar file. Your jar file MANIFEST would reference the JDBC jar file.

    You then deploy this directory as a whole, and not just the jar file.

    Netbeans (and probably Eclipse) creates this automatically.

  5. #5
    tarkowc is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default Problem loading JDBC SQL driver

    I have included the sqljdbc.jar file in the jar file I am creating. I am not using an IDE. I am using the jar program that is part of the SDK.

    Does the code look correct?

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default

    Doesn't work like that.
    You can't include a jar in a jar (without unzipping, something which I personally see as a poor decision).
    Your jar should only contain your code and resources, with a MANIFEST that references any dependent jar files usually relative to your jars location (ie lib/sqljdbc.jar).
    Which is why I talked about a deployment directory.

  7. #7
    tarkowc is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    Please excuse my ignorance but how do i add to the manifest?

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default

    Use the MANIFEST it created in you jar file as a start point and hand carve a new one from that. Then there's an option in the jar command to supply a manifest without having it created for you.

  9. #9
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by tarkowc View Post
    Please excuse my ignorance but how do i add to the manifest?
    You can refer some basic manifest operations here: Manifest Basics

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  10. #10
    tarkowc is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    I downloaded Eclipse and am trying to use that. Eclipe tells me that com.microsoft cannot be resolved to a type. Here is the code that I have put into Eclipse:
    package reserveAssetts;
    import java.sql.*;
    public class ReserveAssetts {

    /**
    * @param args
    */
    public static void main(String[] args) {
    com.microsoft.sqlserver.jdbc.SQLServerDataSource ds = new com.microsoft.sqlserver.jdbc.SQLServerDataSource() ;
    }

    }

    What am I doing wrong?

  11. #11
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default

    Have you added the library (jar file) to the project?

  12. #12
    tarkowc is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    Yes. I added the jar file to the project, but it is still giving me the same error.

  13. #13
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default

    Does that class exist in that jar?
    What happens when you start typing import com.microsoft. etc etc?
    Does it supply you with options after each dot?
    If not then you haven't added the jar file.

  14. #14
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by tarkowc View Post
    Yes. I added the jar file to the project, but it is still giving me the same error.

    in eclipse a way to add a jar is to right-click your project -> Build Path -> Configure Build Path ... -> Libraries and click the Button Add External Jars, navigate to the folder that contains the odbc-jar and select it. if you want to try with manifest look at this site.

  15. #15
    tarkowc is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    Yes that path appears in the jar in the window on the Left, but as I type the dotted path it doesn't show the selections. I will try the suggested Build Path operation and let you know what happens.

  16. #16
    tarkowc is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    I know this is turning into a totally different question, but I don't know if I should create a new thread or continue on this same thread. It compiled successfully in Eclipse. Now how do I create an executable from Eclipse?

  17. #17
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,447
    Rep Power
    18

    Default

    That's a 50/50 judgement call I think. It's all sort of related.
    Not that I can help you, though. My Eclipse is a bit rusty.

Similar Threads

  1. Problem with loading driver
    By b01g in forum New To Java
    Replies: 7
    Last Post: 07-15-2011, 06:41 PM
  2. Loading of JDBC Driver
    By Riyaz.hk77 in forum Advanced Java
    Replies: 11
    Last Post: 11-11-2010, 08:53 AM
  3. Problem finding SQLite JDBC driver
    By PrinceSendai in forum JDBC
    Replies: 9
    Last Post: 08-09-2010, 01:24 AM
  4. JDBC Driver problem
    By Swamipsn in forum New To Java
    Replies: 3
    Last Post: 08-09-2007, 03:55 PM
  5. JDBC driver connection problem
    By creativehacker in forum JDBC
    Replies: 3
    Last Post: 07-10-2007, 09:58 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
  •