I'm trying to design a java applet that connects to a mysql database. I wrote the following code using eclipse and from eclipse my java applet will launch and run just fine. When I click the button it edits the database and everything. I wanted to take it out of the eclipse setting and test it before moving forward with this project and its not working.
Here is my code :
CODE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class BirthdayApplet extends JApplet {
Connection conn;
public void init()
{
setLayout(new FlowLayout());
JButton test = new JButton("Click Me!");
testButton happy = new testButton();
test.addActionListener(happy);
add(test);
try
{
// Load the driver
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
// Connect to the database
conn = DriverManager.getConnection("jdbc:mysql://mysql9.ixwebhosting.com/net20_java", "mat2", "yay1");
}
catch (Exception e) {add(new JLabel(e.getMessage()));}
}
public void start()
{
}
public void stop()
{
}
public void destroy()
{
}
private class testButton implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try {
conn.createStatement().execute("INSERT INTO `people` (`name`, `address`) VALUES ('Start Here', '52 Woot Ave')");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} //Insert a row
}
}
}
I copied all of my class files into a folder as well as the mysql connector files. I wrote up a quick html to test it with this code :
<applet code=BirthdayApplet.class
archive="mysql-connector-java-5.1.7-bin.jar"
width=800 height=600>
</applet>
I've gotten various errors trying to get this to work but with the current configuration it gives me : Communications Link Failure last packet sent to server was 0ms ago.
Project still accesses database without a problem from eclipse and works fine.
Would appreciate any suggestions.
Thank you
This post has been edited by corsen2000: 30 Mar, 2009 - 04:10 PM