Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

When trying to connect, java.lang.ClassNotFoundException;

843854Oct 1 2002 — edited Oct 2 2002
I 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();
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 30 2002
Added on Oct 1 2002
7 comments
593 views