Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/01/2006, 08:55
Avatar de Mephisto
Mephisto
 
Fecha de Ingreso: enero-2006
Ubicación: Mexico DF
Mensajes: 184
Antigüedad: 18 años, 4 meses
Puntos: 3
Perdon por el retraso, he estado algo ocupado en mi trabajo.

Tengo algo parecido a lo que estas haciendo, espero tre sirva...

//AQUI DEFINO LO QUE SE REFIERE A LA CONEXION Y UN OBJETO DE TIPO FRAME QUE ES LA OTRA VENTANA

public class BDMain extends javax.swing.JFrame {

//Inicializa valores para la conexion a la BD
Connection Conexion;
Statement Sentencia;
ResultSet Resultado;
static String Driver = "sun.jdbc.odbc.JdbcOdbcDriver";
static String BdNombre = "Proyecto";
static String BdUrl = "jdbc:odbc:"+BdNombre;
static String BdUser = "";
static String BdPsw = "";

//Declaracion de la ventana de apoyo
DatosEmp Emp = new DatosEmp();
...


//ESTA ES LA FUNCION QUE PARA MI CASO ESTA EN UN MENU EN LA CUAL
//REALIZO LA CONEXION A LA BASE DE DATOS

private void jConectarActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
try{
Class.forName(Driver).newInstance();
Conexion = DriverManager.getConnection(BdUrl,BdUser,BdPsw);
Sentencia = Conexion.createStatement();
jMessages.setText("Conexion a la BD exitosa");
}
catch(Exception e){
jMessages.setText(e.getMessage());
}
}

//ESTA FUNCION ESTA SE REFIERE A OTRO ELEMNTO DEL MENU EL QUE
//LLAMO A LA OTRA VENTANA. SE LE MANDAN LAS VARIABLES DEFINIDAS
private void jBuscaEmpActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
Emp.RecibeCon(Conexion, Sentencia, Resultado);
Emp.show();
}

//////////////////////////////////////////
// EN EL CODIGO DE LA OTRA FRAME

//DEFINO VARIABLES EN LAS QUE SE ALMACENARAN LOS DATOS DE LA
//CONEXION
public class DatosEmp extends javax.swing.JFrame {

Connection Conexion;
Statement Sentencia;
ResultSet Resultado;
...

//DEFINO LA FUNCION QUE RECIBE LOS DATOS DE LA CONEXION
public void RecibeCon(Connection c, Statement st,ResultSet rs){

Conexion = c;
Sentencia = st;
Resultado = rs;

}

// FINALMENTE EJECUTO UNA TRANSACCION Y PEGO LOS DATOS EN CAMPOS
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
try {
// Se realiza la consulta
Resultado = Sentencia.executeQuery( "SELECT Nombre,Ap_Paterno,Ap_Materno "+
"FROM Id_Emp");

//Muestra el primer resultado de la consulta
if(Resultado.next())
{
jNombre.setText(Resultado.getString("Nombre"));
jPaterno.setText(Resultado.getString("Ap_Paterno") );
jMaterno.setText(Resultado.getString("Ap_Materno") );

}
else
{
//Messages.setText("La consulta envio una tabla vacia");
}

} catch( SQLException e ) {
}
catch(Exception e){
}


}
__________________
Saludos...

Todos somos sabios, solo que en diferentes disciplinas...