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

classpath issue jdbc-applet

jered veld
Greenhorn

Joined: Sep 26, 2002
Posts: 6
hi, about a week ago i posted a thread
(http://www.coderanch.com/t/297853/JDBC/java/mysql-jdbc-connection) cuz i was having problems making a connection to a msyql database and kept getting the:
exeption in thread "main" java.lang.ClassNotFoundException rg.gjt.mm.mysql.Driver
error. i resolved this (with the help i got in the thread).
i went on to try and create an applet that will be able to access the same database and encountered the same issue:
java.lang.ClassNotFoundException rg.gjt.mm.mysql.Driver
im wondering if there is something im missing here, that i must change for the applett to function. i set classpath variable in a dos prompt (im running windows2000) and compile the applet and no problems. i go to run in browser and get the exception.
HERE IS CODE:
import java.sql.*;

public class testApplet extends javax.swing.JApplet {

String url = "jdbc:mysql://localhost/people";
String user = "odbc@localhost";
String password = "*******";


public testApplet() {
initComponents();
}

private void initComponents() {
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
getContentPane().setLayout(new java.awt.FlowLayout());

setName("");
jButton1.setText("search");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

getContentPane().add(jButton1);

jTextField1.setPreferredSize(new java.awt.Dimension(250, 21));
getContentPane().add(jTextField1);

jTextField2.setPreferredSize(new java.awt.Dimension(80, 21));
getContentPane().add(jTextField2);

}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
Connection c= DriverManager.getConnection(url,user,password);
Statement s = c.createStatement();
}catch(Exception e){
jTextField1.setText(e.toString());
}
}


private javax.swing.JButton jButton1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
}

any help would be much appreciated. thanks in advance.


java newbie
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

What does your applet tag look like?


GenRocket - Experts at Building Test Data
jered veld
Greenhorn

Joined: Sep 26, 2002
Posts: 6
hi, this is the applet tag:
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="650" height="150" align="baseline"
codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0">
<PARAM NAME="code" VALUE="testApplet.class">
<PARAM NAME="codebase" VALUE=".">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2">
<COMMENT>
<EMBED type=
"application/x-java-applet;version=1.2.2"
width="650" height="150" align="baseline" code="testApplet.class" codebase="."
pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html">
<NOEMBED>
</COMMENT>
NO JAVA 2 SUPPORT FOR APPLET
</NOEMBED>
</EMBED>
</OBJECT>
the applet is loading correctly into the browser no probs there. the applet and html are in the same directory as the sql driver: c:\mysql\ also.
is there something i must change when creating the applet as opposed to the straight console app??
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, here is my applet tag. Notice the "archive" attribute. If your driver is still JAR'd, you may need this.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

if Gregg's suggestion doesn't clear up your problems, try changing your connection to
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
some jvm's have trouble without newInstance().
Jamie
jered veld
Greenhorn

Joined: Sep 26, 2002
Posts: 6
hi thanks for the help. well i can see the crucial line in your tag.
<PARAM NAME="archive"
VALUE="blah blah blah blah">
what exactly should value be though.
i have the mysql jar file in the mysql directory along with the driver *.class files.
c:\mysql\
that is also where i have my testApplet.class file and the .html document. so for java to look for it there how would i word that for VALUE=
thank you very very much. i've been messing with this for way too long i just want to figure it out before i jump out the window.
jered veld
Greenhorn

Joined: Sep 26, 2002
Posts: 6
this works:

thanks a lot greg, your modification to the applet tag was what worked.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath issue jdbc-applet