Skip to main content

Class not found exception error

1 reply [Last post]
sekar_r24
Offline
Joined: 2007-08-11
Points: 0

hi friends

this my prgm code

package ex;
import java.sql.*;

public class Main
{
public static void main(String args[]) throws Exception
{
//System.out.println("Not Connected");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433");
System.out.println("Connected");
PreparedStatement ps = conn.prepareStatement("select * from Products");
ResultSet rs=ps.executeQuery();
while(rs.next())
{
System.out.println(rs.getString(2));
}
}
}

i have added driver to the NetBeans 6.0, While run time it shows following error msg

Exception in thread "main" 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 java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at ex.Main.main(Main.java:12)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

help me to solve the above program

regards,

sekar.r

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lkishalmi
Offline
Joined: 2005-10-11
Points: 0

Create a new class library for your JDBC driver at Tools > Libraries.
Open your project properties. In the Libraries section go to the Run tab and Add Library to add your JDBC driver to your project (runtime only at this time.)