Foros del Web » Programación para mayores de 30 ;) » Java »

Por q no funciona!!!!!

Estas en el tema de Por q no funciona!!!!! en el foro de Java en Foros del Web. Hola soy nuevo en Java y me han pedido hacer algo muy simple; un applet q muestre un campo de una tabla en el servidor. ...
  #1 (permalink)  
Antiguo 27/01/2005, 09:35
Avatar de marcos25  
Fecha de Ingreso: noviembre-2002
Ubicación: España
Mensajes: 164
Antigüedad: 21 años, 5 meses
Puntos: 0
Exclamación Por q no funciona!!!!!

Hola soy nuevo en Java y me han pedido hacer algo muy simple; un applet q muestre un campo de una tabla en el servidor. Ya logré realizar la conexion y mostrar el dato; pero no se por razon no se me actualiza, creo un thread para q realice una consulta cada 3 segundos y vuelva a cargar el dato, pero no me funciona.

Cuando lo pruebo con appletviewer si funciona, pero en el browser no.

Si alguein sabe por q y me lo dice ... le estaria muy agradecido.

Marcos

CODE SOURCE


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();
}
}

}
__________________
Si gato feliX .... ratón tristeX
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:32.