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
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.
Code:
java -cp /XYZ/sqljdbc.jar YourApplication
kind regards,
Jos
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
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)
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
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.
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
Re: add the driver jar file in the classpath.
Quote:
Originally Posted by
vahidbakhtiary
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
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
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