appet con conexion a Mysql
Hola necesito hacer un applet que se conecte con una base de datos de Mysql y muestre el valor de un campo. Hasta aqui ya lo tengo hecho; pero si el valor del campo se modifica; el applet debe mostrar el nuevo valor; logre hacer esto, pero solo me funciona en el appeltviewer y no asi en un browser; sabe alguien por que puede darse esto?
Desde ya muchas gracias.
Aqui añado el codigo fuente.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import java.applet.*;
import java.text.*;
import java.awt.TextField;
public class ver5 extends Applet implements Runnable {
String nombre;
TextField field;
private volatile Thread timer;
public void main (String[] args)
{
init();
}
public void repaint1()
{
try
{
Class.forName ("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://192.168.1.228/test", "espia", "ESPIAAA");
Statement stm = con.createStatement();
ResultSet rs = stm.executeQuery("select * from cliente;");
while(rs.next())
{
nombre = rs.getString("nombre");
addItem(nombre);
}
rs.close();
stm.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void init()
{
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridBag);
field = new TextField();
field.setEditable(false);
//Set the layout manager so that the text field will be
//as wide as possible.
setLayout(new java.awt.GridLayout(1,0));
//Add the text field to the applet.
add(field);
validate();
addItem("Jala!... ");
}
void addItem(String newWord) {
//String t = field.getText();
field.setText(newWord);
repaint();
}
public void start()
{
timer = new Thread(this);
timer.start();
}
public void stop()
{
timer = null;
}
public void run()
{
Thread me = Thread.currentThread();
while (timer == me)
{
try
{
Thread.currentThread().sleep(5000);
}
catch (InterruptedException e)
{
}
repaint1();
}
}
}
Desde ya muchas gracias.
Aqui añado el codigo fuente.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import java.applet.*;
import java.text.*;
import java.awt.TextField;
public class ver5 extends Applet implements Runnable {
String nombre;
TextField field;
private volatile Thread timer;
public void main (String[] args)
{
init();
}
public void repaint1()
{
try
{
Class.forName ("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://192.168.1.228/test", "espia", "ESPIAAA");
Statement stm = con.createStatement();
ResultSet rs = stm.executeQuery("select * from cliente;");
while(rs.next())
{
nombre = rs.getString("nombre");
addItem(nombre);
}
rs.close();
stm.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void init()
{
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridBag);
field = new TextField();
field.setEditable(false);
//Set the layout manager so that the text field will be
//as wide as possible.
setLayout(new java.awt.GridLayout(1,0));
//Add the text field to the applet.
add(field);
validate();
addItem("Jala!... ");
}
void addItem(String newWord) {
//String t = field.getText();
field.setText(newWord);
repaint();
}
public void start()
{
timer = new Thread(this);
timer.start();
}
public void stop()
{
timer = null;
}
public void run()
{
Thread me = Thread.currentThread();
while (timer == me)
{
try
{
Thread.currentThread().sleep(5000);
}
catch (InterruptedException e)
{
}
repaint1();
}
}
}
¿Qué error te da?
No sé si sabes que un applet sólo puede conectarse al servidor del que cuelga. No puede hacer conexiones a ningún otro sitio.
Para conectar al propio host, creo que hay métodos tipo "getCodeBase" o asà para recuperarlo.
Pero vamos, que ayudarÃa si pudiésemos ver el error que da...
Salu2
Ken
No sé si sabes que un applet sólo puede conectarse al servidor del que cuelga. No puede hacer conexiones a ningún otro sitio.
Para conectar al propio host, creo que hay métodos tipo "getCodeBase" o asà para recuperarlo.
Pero vamos, que ayudarÃa si pudiésemos ver el error que da...
Salu2
Ken
