aspose file tools*
The moose likes JDBC and the fly likes An JDBC problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "An JDBC problem" Watch "An JDBC problem" New topic
Author

An JDBC problem

Timothy Wong
Greenhorn

Joined: Jan 21, 2001
Posts: 3
Hi,
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?
NT+SP4+JDK1.3
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);
worker.start();
}
}
public void run() {
String url = "jdbc dbc :people";
String query = "select First from csv";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(Exception ex) {
setError(""+ex);
return;
}
try {
Vector results = new Vector();
Connection con = DriverManager.getConnection(url,"sa", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String s = rs.getString("First");
//float f = rs.getFloat("PRICE");
String text = s;// + " " + f;
results.addElement(text);
}
stmt.close();
con.close();
setResults(results);
} 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);
return;
}
// 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.
repaint();
}
private synchronized void setResults(Vector results) {
queryResults = results;
worker = null;
// And ask AWT to repaint this applet.
repaint();
}
}
============================================================
<html>
<head>

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

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

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

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 {
Class.forName("acs.jdbc.Driver");
}
catch(Exception ex) {
setError(""+ex);
return;
}
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: http://aspose.com/file-tools
 
subject: An JDBC problem