applet mysql
Hello,
I am trying to write an applet that talks to a mySQL. I have a program that works as a stnd alone program but when I put it in an applet, I get the following error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Below is my code? java then html
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class Loom extends Applet implements ActionListener{
Connection dbConn; // Setup a connection with the OS
Statement dbCmdText; // Contains SQL commands
String dbSQL; // Temp String for building SQL command
ResultSet dbRecordset; //
ResultSet dbQuerySet;
JTextField nameField;
JButton button1;
JButton button2;
private String [] rowstr ={};
private String [] qtystr ={};
private String [] casostr ={};
private String [] vintstr ={};
private String [] winestr ={};
private String [] descstr ={};
private String [] ownstr ={};
private String [] inty = {};
// private String [] casostr ={};
private JComboBox cboInventory = new JComboBox();
// JButton button3;
public void init() {
try {
createGUI();
}
catch (Exception e) {
System.err.println("createGUI didn't successfully complete");
}
// casostr = new String[55];
// qtystr = new String[55];
// vintstr = new String[55];
winestr=new String[55];
// descstr=new String[55];
// ownstr=new String[55];
try{
String driver = "com.mysql.jdbc.Driver";
System.out.println( "=> loading driver:" );
Class.forName( driver );
System.out.println( "OK" );
String strConn;
System.out.println("Attempting to establish a database connection");
try
{
// Generic SUN driver for databases
String ibid = "jdbc:mysql://localhost/test";
dbConn = DriverManager.getConnection(ibid, "root", "r");
// if you cannot find the database, handle it here
if (dbConn == null) // Is the Connection working?
{
System.out.println("Connection to database failed");
}
}
catch (Exception e)
{
int q =1;
String pedro =winestr[q];
nameField = new JTextField(40);
add(nameField);
nameField.setText("cripees");
}
String gooey="SELECT * FROM hag";
dbCmdText = dbConn.createStatement();
dbRecordset = dbCmdText.executeQuery(gooey);
ResultSetMetaData rsmd = dbRecordset.getMetaData();
int k=50;
int w=0;
while (dbRecordset.next())
{
rowstr[w]=dbRecordset.getString("row_id");
casostr[w]=dbRecordset.getString("caso");
qtystr[w]=dbRecordset.getString("qty");
vintstr[w]=dbRecordset.getString("vintage");
winestr[w]=dbRecordset.getString("winery");
descstr[w]=dbRecordset.getString("description");
ownstr[w]=dbRecordset.getString("owner");
System.out.println();
w++;
} // end of while
}
catch (Exception e)
{
int q =1;
String pedro =winestr[q];
nameField = new JTextField(30);
add(nameField);
nameField.setText(e.toString());
// System.err.println(e.toString());
} // end of catch
}
private void createGUI() {
setLayout(new FlowLayout());
add (button1 = new JButton("Load Wine List"));
add (button2 = new JButton("Delete this Wine"));
// add (button3 = new JButton("Add a Wine to the Database"));
button1.addActionListener(this);
button2.addActionListener(this);
cboInventory = new JComboBox();
cboInventory.addActionListener(new MomboListener());
add(cboInventory);
String sqlString;
}
public void actionPerformed(ActionEvent evt)
{
// Here we will ask what component called this method
if (evt.getSource() == button1)
// So it was the okButton, then let's perform his actions
// Let the applet perform Paint again.
// That will cause the aplet to get the text out of the textField
// again and show it.
// repaint();
System.out.println("Not here!");
// Actions of the wrongButton
else if (evt.getSource() == button2)
{
// Change the text on the button for fun
button2.setLabel("Not here!");
// Changes the text in the TextField
nameField.setText("That was the wrong button!");
// Lets the applet show that message.
// repaint();
}
}
private class MomboListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Object goose = event.getSource();
if (goose == cboInventory){
System.out.println("OK");
}
}
}
public void destroy()
{
System.out.println("destroy method called");
}
}
HTML
<HTML>
<Head>
<Title>Wine Storage</Title>
<Body>
<P> <center><Applet Code="Loom.class" align="center" width="850" height="750" VSPACE="50"
</Applet> </P>
</Body>
</HTML>
Any ideas
|