LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2006, 10:01 AM   #1
Peter Shepard
Member
 
Registered: Apr 2005
Posts: 96

Rep: Reputation: 15
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
 
Old 06-13-2006, 10:32 AM   #2
fedora4002
Member
 
Registered: Mar 2004
Posts: 135

Rep: Reputation: 15
Did you put Mysql driver files mysqlxxxxxx.jar in the same place with your class file? Applet can not find Mysql so it gives an error.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 17 09-17-2014 02:13 PM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. suziecorbett Linux - Software 8 10-09-2008 01:52 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
Java applet error: "Applet Failed" nro Programming 1 08-28-2004 05:52 PM
MySQL not allowing connections from Applet peteABK Linux - Newbie 1 11-04-2003 09:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration