If you get a java.lang.ClassNotFoundException error when loading a database driver using the statement:
Class.forName({nameOfYourDriverWhateverItIs}).newInstance();
You can either:
Set CLASSPATH in DOS
Go into DOS (Start/Run/cmd.exe):
set CLASSPATH=.;{pathToYourJarFile}
For example, if your jar file is at: C:/Program
Files/java/jdk1.6.0_01/lib/mysql-connector-java-5.0.6-bin.jar,
Type:
set CLASSPATH=.;C:/Program Files/java/jdk1.6.0_01/lib/mysql-connector-java-5.0.6-bin.jar
Now,
javac YourJavaFile.java
java YourJavaFile
That’s all. But it won’t work if you’re trying to run code in Netbeans.
Set Your Project’s Classpath in Netbeans
If you’re using […]
Archive for the 'Java' Category
JDBC ClassNotFoundException (NetBeans, Classpath, Java) • Saturday, June 16th, 2007