This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

classpath issue jdbc-applet  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your applet tag look like?
 
jered veld
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, here is my applet tag. Notice the "archive" attribute. If your driver is still JAR'd, you may need this.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this works:

thanks a lot greg, your modification to the applet tag was what worked.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!