Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2012
    Posts
    14
    Rep Power
    0

    Default add the driver jar file in the classpath.

    hi
    i when use this code :
    Class.forName("com.microsoft.sqlserver.jdbc.Driver ");
    i meet error :
    java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at connecturl.ConnectURL.main(ConnectURL.java:27)
    i search into google and i understant that must download sqljdbc.jar and set it into classpath
    please help me how to it do

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: add the driver jar file in the classpath.

    First you need to have that jar file available on your hard disk somewhere; suppose it's stored in a directory /XYZ. You have to add the absolute path /XYZ/sqljdbc.jar to your classpath, e.g.

    Java Code:
    java -cp /XYZ/sqljdbc.jar YourApplication
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Jun 2012
    Posts
    14
    Rep Power
    0

    Default Re: add the driver jar file in the classpath.

    thanks for your answer
    i write this code :
    java -cp e:\sql\sqljdbc_4.0\enu\sqljdbc.jar e:\java\sample4\src\ConnectToDB

    but i meet this error
    Error:Could not find or load main class e:\java\sample4\src\ConnectToDB

    please help me
    thanks

  4. #4
    Join Date
    Jun 2012
    Posts
    14
    Rep Power
    0

    Default Re: add the driver jar file in the classpath.

    so i flowing this steps:

    Windows Click Start > Control Panel > System.

    Click the Advanced tab, and then click Environment Variables.

    In the System variables list, select the CLASSPATH variable, and then click Edit.
    Notes:
    If CLASSPATH is not already listed under System variables, click New and type CLASSPATH in the Variable name field.

    Add the following to the end of the Variable value field:
    ;jdbc_path\sqljdbc.jar
    In the Edit User Variable window, click OK, and then click OK in the Environment Variables and System Properties windows.

    but when i run this code :
    Class.forName("com.microsoft.sqlserver.jdbc.Driver ");
    i meet this error :
    java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at ConnectToDB.main(ConnectToDB.java:11)

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: add the driver jar file in the classpath.

    You don't have a database problem; your problem is that you don't know anything about running classes and the classpath; you should go back to the tutorials and study how it's done. A monkey see, monkey do approach is never beneficial.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default Re: add the driver jar file in the classpath.

    Do not use the CLASSPATH environment variable.
    That is poor practice is utterly useless in a production environment.

    Take Jos' advice and go to the tutorials.
    One of the "basics" ones covers classpaths.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Join Date
    Jun 2012
    Posts
    14
    Rep Power
    0

    Default Re: add the driver jar file in the classpath.

    thanks for your answer

    i'll connect to sql 2008 but i can't do it
    please show me a sample code for fetch data from sql

    thanks

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: add the driver jar file in the classpath.

    Quote Originally Posted by vahidbakhtiary View Post
    thanks for your answer

    i'll connect to sql 2008 but i can't do it
    please show me a sample code for fetch data from sql

    thanks
    You did read the previous two replies did you?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Join Date
    Jun 2012
    Posts
    14
    Rep Power
    0

    Default Re: add the driver jar file in the classpath.

    thanks for your answer
    that please how to set the classpath
    i use from CLASSPATH environment variable in last post but i don't work

    please help me for solve it
    thanks

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: add the driver jar file in the classpath.

    You've been given a link to the tutorial. Now go through it, starting from the 'Hello World' sample program.

    Until you know what parameter to pass to java.exe to launch a program via the main(...) method of a class, there's really no point in trying to understand how to use other flags like -cp.

    And get rid of the CLASSPATH environment variable. At least until you understand exactly what it is all about.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 09-29-2011, 10:39 AM
  2. How to configure Java mysql driver and CLASSPATH?
    By fish309 in forum New To Java
    Replies: 14
    Last Post: 07-20-2010, 09:51 AM
  3. Load A Property File From Classpath?
    By miko5054 in forum New To Java
    Replies: 2
    Last Post: 06-29-2010, 12:06 PM
  4. setting path and classpath variables from batch file -
    By manojsingh.manoj@gmail.co in forum Advanced Java
    Replies: 1
    Last Post: 09-15-2009, 11:50 AM
  5. Replies: 10
    Last Post: 10-30-2008, 04:57 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
  •