Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 309,232 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,767 people online right now. Registration is fast and FREE... Join Now!




Java Applet Help

 

Java Applet Help, java with mysql

corsen2000

30 Mar, 2009 - 03:47 PM
Post #1

New D.I.C Head
*

Joined: 2 Feb, 2009
Posts: 9



Thanked: 3 times
My Contributions
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

User is offlineProfile CardPM
+Quote Post


Posts in this topic

Fast ReplyReply to this topicStart new topic

Time is now: 11/26/09 08:51AM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month