Results 1 to 17 of 17
  1. #1
    edzet is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default classpath problem, out of ideas

    Hi,
    I want to work with the Microsoft SQL JDBC driver.

    I added it to my class path: .;C:\sqljdbc\enu\sqljdbc.jar"

    I get a Class not found error on "Class.forName("com.microsoft.sqlserver.jdbc.SQLSe rverDriver");"

    I read the the docs (Using the JDBC Driver) and tried all the things I know (direct on c:/, in the lib dir of the VM, same dir as the jar I start).

    Now I'm out of idea's...

    Suggestions are welcome!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default

    You're launching from a jar, so the CLASSPATH is not used.
    Never mind that you really shouldn't use the system CLASSPATH anyway.
    Does the manifest in your jar file reference the driver jar?

  3. #3
    JavaRulez is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    Here, this is copied from a shell script that launches one of my java programs which utilizes a JDBC driver:

    Java Code:
    java -classpath ./postgresql-8.4-701.jdbc3.jar:./ -Djdbc.drivers=org.postgresql.Driver
    The JDBC jar is located in the same directory, as indicated by ./

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default

    So you're not running a jar?

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You are really in a mess. Your run command does not say which to run.
    You are giving your program the postgres driver and it's telling you that it can't find the sqlserver driver.

  6. #6
    JavaRulez is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    Please note, I am not the original poster, I was just trying offer help. Also, I eliminated the class name from the run command, as well as the full path to JDK bin dir, as they aren't relevant.
    Last edited by JavaRulez; 05-07-2010 at 10:00 AM.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default

    Ah...oopsie!

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by JavaRulez View Post
    Please note, I am not the original poster, I was just trying offer help.
    Ah well that explains it.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default

    However, if the OP is running from a jar then -cp is ignored, which is why I was asking about the manifest.

  10. #10
    JavaRulez is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    However, if the OP is running from a jar then -cp is ignored, which is why I was asking about the manifest.
    I was not aware of this, in fact, From the Java tutorials, it is implied that -classpath will work
    By using the Class-Path header in the manifest, you can avoid having to specify a long -classpath flag when invoking Java to run the your application.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default

    Quoting from the sun docs for java, the -jar switch:

    "When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored."

  12. #12
    edzet is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default SOLVED, Thanks!

    I found the command line to meet my needs:

    java -cp ./webharvest_all_2.jar;./sqljdbc4.jar CommandLine

    webharvest_all_2.jar is the jar I want to run,
    CommandLine is the main Class in this package.

    I use a ';' instead of the ':' in the classpath, cause mine is a windows machine.

    Setting the JDBC driver is done within the webharvest app, so I truncuated it form the command line.

    There is nu classpath in the webharvest manifest, so in this case it worked..

    Thank you both!

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default

    Well, it's not because there is no classpath in the manifest.
    It's because you are not doing "java -jar".

    I'd recommend sorting your jar file out.

  14. #14
    JavaRulez is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    I agree, I was just offering a bandage for the problem.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default

    I get nervous about bandage fixes.
    They're OK occasionally, but I've worked on the odd project where there were so many bandages (as opposed to proper fixes) you couldn't actually see the patient anymore...:)

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

    Default

    Quote Originally Posted by edzet View Post
    Suggestions are welcome!

    use Apache Ant it's very easy to install it and once it runs it's also very easy to configure. since i use ant all my problems with classpath, jar-files, external libraries and so on while building a runnable jar have vanished ;)

  17. #17
    g_ayyappan is offline Member
    Join Date
    Apr 2010
    Posts
    4
    Rep Power
    0

    Default

    thought worth mentioning...

    Are you using exactly the same driver name as mentioned in the post. "com.microsoft.sqlserver.jdbc.SQLSe rverDriver"? Hope you did not use a space character in your actual code.

Similar Threads

  1. Replies: 8
    Last Post: 11-05-2010, 10:26 PM
  2. mysql classpath ubuntu problem
    By munish in forum JDBC
    Replies: 18
    Last Post: 08-22-2010, 01:55 AM
  3. classpath problem
    By Nifras in forum New To Java
    Replies: 6
    Last Post: 11-28-2009, 04:49 PM
  4. classpath problem
    By shwein in forum New To Java
    Replies: 4
    Last Post: 04-01-2009, 12:32 PM
  5. Problem with CLASSPATH for STRUTS
    By bhupal4all in forum Web Frameworks
    Replies: 2
    Last Post: 11-07-2008, 05:48 AM

Posting Permissions

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