-
Exception
Following is the code that I have written to get connection to SQL Server:
public class Main {
public static void main(String[] args) {
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlser ver://localhost:1433;DATABASENAME=Test","mimdad","aaa");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
and following is the exception that I am getting at the Class.forName().
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.j ava:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at sqlserver.Main.main(Main.java:39)
Can anybody help me.
-
hi,
It is clear that you dont have the sqljdbc.jar in your class path. This is the jar file which supports the JDBC 3 Driver to connect with Database.
Regards
Felix T