When trying to connect, java.lang.ClassNotFoundException;
843854Oct 1 2002 — edited Oct 2 2002I can't seem to resolve this error:
SearchServlet.java [48:1] unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown
db.connect();
^
=========The error is in the following Servlet:
SinglesSearch.Database db=new SinglesSearch.Database();
db.connect(); //this line throws the exception
=========
I've searched the web for servlets connecting to the database, but couldn't find anything that would help me figure out this issue.
Can you help ?
thanks,
Dennis
P.S.
My database helper class.
/*
* Database.java
*/
package SinglesSearch;
import java.sql.*;
import java.io.*;
public class Database {
//Helper Class -- Takes care of DB connections and SQL
/** Creates a new instance of Database */
public String dbURL = "jdbc:mysql://localhost/singles";
public String dbDriver = "com.mysql.jdbc.Driver";
private Connection dbCon;
public Database() {
super();
}
public boolean connect() throws ClassNotFoundException,SQLException
{ //Connect to DB
Class.forName(dbDriver);
dbCon = DriverManager.getConnection(dbURL,"test", "test");
return true;
}
public void close() throws SQLException
{ //Close connection to DB
dbCon.close();
}
}