When try to compile my java code I get the following error message.
"unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown"
I'm using BlueJ as my compiler. I have the following in my autoexec.bat file.
set CLASSPATH=C:\mysql-connector-java-3.0.16-ga\mysql-connector-java-3.0.16-ga\mysql-connector-java-3.0.16-ga-bin.jar;%CLASSPATH%
I'm running Windows XP Home edition. I tried setting the variable by right clicking My Computer / Properties / Advanced tab and then in the environment Variables. That did not help ether.
My goal is to connect to a mySQL database. I have pasted the following code. Any help is greatly appriciated. Thanks.
import java.io.*;
import java.lang.String;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.sql.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class stockSetupTest
{
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
private Connection connection; // new code
private Statement statement; // new code
void getConn()
{
try {
Class.forName(JDBC_DRIVER);
// the line above this is where I have trouble with my compiler
// used this line and it didn't work // Class.forName(JDBC_DRIVER).newInstance();
connection = DriverManager.getConnection("jbdc:mysql://localhost:3306/stocks"); // user and password has been removed.
statement = connection.createStatement(); // new code to create statment
}
catch (SQLException ex)
{ // handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}