Error with JDBC Driver
hi, i am using sqljdbc.jar in a java applet and i am using Netbeans for development. i am able to connect with the SQL Server from the IDE. however, when i try to debug the SQL part of the code, i am getting an exception at :
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl="jdbc
qlserver://localhost:49182;databaseName=NanoBase;";
Connection con = java.sql.DriverManager.getConnection(connectionUrl, "test", "Walt787sop289");where it says that it cannot find the class. i am also putting down the exception information.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.javaws.Launcher.executeApplication(Launcher.java:1273)
at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1219)
at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1066)
at com.sun.javaws.Launcher.run(Launcher.java:105)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerDriver
at VncViewer.performSql(VncViewer.java:115)
at VncViewer.readParameters(VncViewer.java:743)
at VncViewer.init(VncViewer.java:152)
at VncViewer.main(VncViewer.java:53)
... 9 more
Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at com.sun.jnlp.JNLPClassLoader.findClass(JNLPClassLoader.java:256)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
i am currently using java web start to debug the application. earlier, the application was running smoothly during debug (when not being run through java web start), but was failing to run when started externally say within a html file as an applet. however, when i used java web start, the exception is being pointed to the line in bold. i have added sqljdbc.jar to the list of libraries and have added it under the compile as well as the run time configuration. i would appreciate if this exception could be resolved. if i have to configure anything in the classpath, pls suggest how i can configure it under netbeans.
regards,
anant
All Replies
Hi Anant,
Yes, you will need to add the sqljdbc.jar file to the classpath of NetBeans. You can follow the information on the NetBeans website (http://www.netbeans.org/kb/55/using-netbeans/project_setup.html#96961) to add the sqljdbc.jar file to the project classpath.
Jimmyhi Jimmy, thanx for the post. however, i have done whatever the link suggests. in fact, i have mentioned this in my earlier post. however, i still get the error even though i checked the 'build projects on classpath'.
regards,
anant
- anant,
I am going at the moment through a very similar issue than the one you described above.
I'm using Eclipse and trying to connect to MS SQL Server 2008 using sqljdbc.jar in a Java servlet.
I'm getting the same exception as you i.e. java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerDriver.
I've been looking into this for two days and although I can see numerous posts here and there related to similar issues, they always come down to editing the Class Path, which I have done in Eclipse as well as by modifying my system CLASSPATH env. variable under Windows Vista, and this in different fashions with no success. The weird thing is that printing out what is in System.getProperty("java.class.path") returns indeed the full path of sqljdbc.jar.
Did you manage to resolve the issue ? If yes then I would be really grateful if you could point me to a solution.
Regards,
- Luc - Luc,
Are you able to successfully use the JDBC driver outside of Eclipse? If so, then I think you might be better served to talk to IBM about this issue. Here at Microsoft, we don't have much experience with Eclipse.
Evan- Proposed As Answer byEvan BasalikMSFTTuesday, November 17, 2009 9:42 PM


