School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,165 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,964 people online right now. Registration is fast and FREE... Join Now!



Java Applet Help

Java Applet Help java with mysql Rate Topic: -----

#1 corsen2000  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 02-February 09


Dream Kudos: 0

Posted 30 March 2009 - 03:47 PM

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 :

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 March 2009 - 04:10 PM

Was This Post Helpful? 0
  • +
  • -


#2 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 30 March 2009 - 04:10 PM

Your database and your applet are n the same server ?
Was This Post Helpful? 0
  • +
  • -

#3 corsen2000  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 02-February 09


Dream Kudos: 0

Posted 30 March 2009 - 04:13 PM

I'm not sure. I use the ftp login to place my applet stuff on the server where my web page is. I don't if that's the server they host my database off or what.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 30 March 2009 - 04:17 PM

View Postcorsen2000, on 30 Mar, 2009 - 04:13 PM, said:

I'm not sure. I use the ftp login to place my applet stuff on the server where my web page is. I don't if that's the server they host my database off or what.

Better to check
An Applet, unless it is a "Signed" applet can touch the file system of any host other than the one it was download from
Was This Post Helpful? 0
  • +
  • -

#5 corsen2000  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 02-February 09


Dream Kudos: 0

Posted 30 March 2009 - 04:21 PM

Any idea why it would work just fine from the eclipse launcher?
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 30 March 2009 - 04:27 PM

View Postcorsen2000, on 30 Mar, 2009 - 04:21 PM, said:

Any idea why it would work just fine from the eclipse launcher?

From your launcher it is not really an Applet :) I never tried it but I should try it once.

And the database might be on your system.

The principle behind all that (and why Java Applet were developped) is that it should be safe to download an Applet inside your internet browser because it cannot harm your system because the Applet does not have access to your file system.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month