ClassNotFound Error on Linux
Posted by: Paul K
Date: December 30, 2004 10:14AM

Hi, I'm trying to figure out if I can even do this; I have a linux box (redhat 9.1) running Apache/2.0.48 (Unix). I have installed java runtime 1.4.2_04. I have Mysql 4.0.13 and MySQL J installed and the jar is mysql-connector-java-3.0.16-ga-bin.jar.

I have the jar file in the JAVA_HOME/jre/lib/ext directory and my CLASSPATH is set to point to the directory which houses the jar and the com/mysql/jdbc/Driver path.

When I run my applet from the localhost machine it runs fine in Firefox, it connects and returns a recordset. Same if I run in Netbeans. The problem arises when I try to run it from another machine, a Windows 2000 box with I.E. 6. I get the standard class java.lang.ClassNotFoundException error when doing the
Class.forName("com.mysql.jdbc.Driver").newInstance();
I moved the applet .class file to the htdocs directory under Apache before I tried the remote connection.

Can I run the applet from a remote machine and if so, why do I get the following error in the Apache error log:
[error] [client 10.86.8.181] File does not exist: /usr/local/apache2/htdocs/com
It looks like it is trying to look for the com/mysql.... classpath from the web directory. I'm really new to this so any help would be greatly appreciated. Here is my code:

import java.applet.Applet;
import java.awt.Graphics;
import java.sql.*;

public class test2 extends Applet {

StringBuffer buffer;

public void init() {
buffer = new StringBuffer();

addItem("initializing... ");
}

void addItem(String newWord) {
System.out.println(newWord);
buffer.append(newWord);
repaint();
}

public void paint(Graphics g) {
//Draw a Rectangle around the applet's display area.
g.drawRect(0, 0, size().width - 1, size().height - 1);

//Draw the current string inside the rectangle.
g.drawString(buffer.toString(), 5, 15);

Connection conn;
String url = "jdbc:mysql://127.0.0.1/nwn?user=paul";
Statement stmt = null;
ResultSet rs = null;
int cnt = 0;

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
g.drawString("Vendor State:" + ex.getMessage(), 5, 30);
g.drawString("Vendor State:" + ex.getClass(), 5, 45);
}
try {
conn = DriverManager.getConnection(url, "paul", "xxxxx");
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT pcname from player");
int linecnt = 20;
while (rs.next()) {
linecnt = linecnt + 15;
cnt++;
String player = rs.getString(1);
g.drawString("Name: "+player+" Counter: "+cnt, 5, linecnt);
}
} catch (Exception ex) {
g.drawString("Vendor State:" + ex.getMessage(), 5, 60);
g.drawString("url:" + url, 10, 75);
}
}
}

Thanks,

Paul

Options: ReplyQuote


Subject
Written By
Posted
ClassNotFound Error on Linux
December 30, 2004 10:14AM
December 30, 2004 02:04PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.