problem connecting to mysql with applet

hey guys, java newbie here...

Having some trouble connecting to a mysql database located on my local box. Simple,, no username/password, just playing around and trying to connect. Pertenant information: JDK 1.5.0_6, Netbeans IDE 5.0, Mysql. I'm running a java applet, and I'm able to get a connection just fine when I run the applet from the IDE, but not when I go to the web browser. Heres my code:

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

/**

*

* @author hobeau

*/

publicclass NewAppletextends java.applet.Applet{

/** Initializes the applet NewApplet */

publicvoid init(){

try{

java.awt.EventQueue.invokeAndWait(new Runnable(){

publicvoid run(){

initComponents();

}

});

}catch (Exception ex){

ex.printStackTrace();

}

}

/** This method is called from within the init() method to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

privatevoid initComponents(){

jFrame1 =new javax.swing.JFrame();

jLayeredPane1 =new javax.swing.JLayeredPane();

jButton1 =new javax.swing.JButton();

jLabel1 =new javax.swing.JLabel();

setLayout(new java.awt.BorderLayout());

jButton1.setText("jButton1");

jButton1.addMouseListener(new java.awt.event.MouseAdapter(){

publicvoid mouseClicked(java.awt.event.MouseEvent evt){

jButton1MouseClicked(evt);

}

});

jButton1.setBounds(20, 50, 73, 23);

jLayeredPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

jLabel1.setText("jLabel1");

jLabel1.setBounds(10, 10, 240, 14);

jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

add(jLayeredPane1, java.awt.BorderLayout.CENTER);

}// </editor-fold>

privatevoid jButton1MouseClicked(java.awt.event.MouseEvent evt){

try{

Class.forName("org.gjt.mm.mysql.Driver");

Connection databaseConnection = DriverManager.getConnection("jdbc:mysql://localhost/test");

jLabel1.setText(databaseConnection.toString());

}catch(ClassNotFoundException cnfe){

jLabel1.setText(cnfe.toString());

}catch(SQLException sqle){

jLabel1.setText(sqle.toString());

}

}

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JFrame jFrame1;

private javax.swing.JLabel jLabel1;

private javax.swing.JLayeredPane jLayeredPane1;

// End of variables declaration

}

As you can see, this is about as basic as it gets. I downloaded the connection drivers from mysqls website and loaded them and it works fine when I run it from the IDE. But when I try to run it from the web browser, I get an error message that says "java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver". I'm sure I'm doing something stupid, but I'm not quite sure what. Can anyone help? Thanks!

[5251 byte] By [hobeaua] at [2007-10-2 12:58:47]
# 1

>Class.forName("org.gjt.mm.mysql.Driver");

This class has to be in your applet's classpath, which is specified in the <applet> element. Yours must be incorrect, and this has nothing to do with the code you are posting, but rather the HTML's <applet> element (and attributes / child elements).

> DriverManager.getConnection("jdbc:mysql://localhost/test");

The next problem after you fix the above is likely going to be that your applet is attempting to make a network connection to something other than the hosting server's URL (applets are not allowed to do this unless you "sign" them or otherwise change the applet security policy).

This shouldn't be an applet. Or the applet should just talk to servlets, where the database stuff happens on the server side from the servlet.

warnerjaa at 2007-7-13 10:17:08 > top of Java-index,Java Essentials,Java Programming...
# 2
ah. Thanks for the info. Good learning experience.
hobeaua at 2007-7-13 10:17:08 > top of Java-index,Java Essentials,Java Programming...