Question

I am setting up sql server jdbc driver to my IDE, But this exception occur:

Exception in thread "main" java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    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.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at SqlServerTests.t1.main(t1.java:10)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

My sqljdbc_4.0 folder is in C:\Users\Sajjad\Desktop\IntelliJ IDEA Projects\src path.

I add this directory to library of IDE.

Was it helpful?

Solution

That's not the best place for that JAR.

I usually create a /lib folder where I put all my 3rd party JARs.

Then I configure my project to add a library that points to all the contents of that /lib folder and give that library to my module as a dependency.

It's not hard to do. You just haven't set up your project in IntelliJ properly.

Stop putting stuff randomly on your desktop. Proper organization matters.

I create a single folder for each IntelliJ project that I have. Under that I usually have /src where all my .java source files go, /lib for 3rd party JARs, /resources for things like .xml configuration files, /test for JUnit test .java files, etc.

I create a library pointing to the /lib folder and make that a module dependency.

OTHER TIPS

Try to download 'mysql connector jar' file from maven if you don't have one. Then after click file-> Project Structure -> +(sign) -> search for your download -> press OK. And you are done. Re-run your program again you'll see.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top