File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes An JDBC problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "An JDBC problem" Watch "An JDBC problem" New topic

An JDBC problem

Timothy Wong

Joined: Jan 21, 2001
Posts: 3
The following applet can be compiled with no error, but when I run it in an HTML file, statement < Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");> will produce an exception: java.lang.classNotFoundException why?
Thanks for your kindly help!
import java.applet.Applet;
import java.awt.Graphics;
import java.util.Vector;
import java.sql.*;
public class test extends Applet implements Runnable {
private Thread worker;
private Vector queryResults;
private String message = "Initializing";
public synchronized void start() {
// Every time "start" is called we create a worker thread to
// re-evaluate the database query.
if (worker == null) {
message = "Connecting to database";
worker = new Thread(this);
public void run() {
String url = "jdbc dbc :people";
String query = "select First from csv";
try {
} catch(Exception ex) {
try {
Vector results = new Vector();
Connection con = DriverManager.getConnection(url,"sa", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while ( {
String s = rs.getString("First");
//float f = rs.getFloat("PRICE");
String text = s;// + " " + f;
} catch(SQLException ex) {
setError("SQLException: " + ex);
public synchronized void paint(Graphics g) {
// If there are no results available, display the current message.
if (queryResults == null) {
g.drawString(message, 5, 50);
// Display the results.
g.drawString("Prices of coffee per pound: ", 5, 10);
int y = 30;
java.util.Enumeration enum = queryResults.elements();
while (enum.hasMoreElements()) {
String text = (String)enum.nextElement();
g.drawString(text, 5, y);
y = y + 15;
private synchronized void setError(String mess) {
queryResults = null;
message = mess;
worker = null;
// And ask AWT to repaint this applet.
private synchronized void setResults(Vector results) {
queryResults = results;
worker = null;
// And ask AWT to repaint this applet.

<title>Welcome To Microsoft Personal Web Server</title>
<applet code=test.class height=300 weight=300>

[This message has been edited by Thomas Paul (edited January 22, 2001).]
Peter Tran

Joined: Jan 02, 2001
Posts: 783
Try Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
wayne hua

Joined: Jan 14, 2001
Posts: 5
I changed the JDBC setting in your program (according to my localhost), and your code run fine.
You can check url, classname, user name and password to see whether it is compatible with your local configuration.
Here is the revised code (just show the changed portion):
public void run() {
String url = "jdbc:avenir:localhost:5000:c:\\My documents\\coldfusion\\housing.mdb";
String query = "select name from seeker";
try {
catch(Exception ex) {
try {
Vector results = new Vector();
Connection con = DriverManager.getConnection(url,"Admin", "");
Good luck.

Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
ClassNotFoundException always means what it says. The Java Virtual Machine could not locate the class. In this case, the JVM is the JVM inside the browser. You need to make sure that rt.jar is in the classpath used by the browser.
I agree. Here's the link:
subject: An JDBC problem
It's not a secret anymore!