I have been trying to create a simple database application in JAVA using JDBC. So far all my attempts have been unsuccessful in even loading the driver. Understand that I'm novice in Java and just started learning. Here are my steps:
- Start > System > Advanced System properties > Environment Variables: Added CLASSPATH=[path to sqljdbc41.jar]
- Added the Driver in the Netbeans

Added the following code:
public class DataSample { public static void main(String[] args) throws Exception{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection cnn=DriverManager.getConnection ("jdbc:sqlserver://localhost;databaseName=AdventureWorks;"); Statement st = cnn.createStatement(); ResultSet rs =st.executeQuery("select * from test");
The program always give this exception:
Exception in thread "main" java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:260) at datasample.DataSample.main(DataSample.java:21) Java Result: 1


