Hello all!
I want to pass a value of one class to another class, but the classes are in different files.
I'm going to post both methods and remember they are in different classes
Ok from this method i want to pass the value of the variables Nombre, Apellido
below.
public void seleccion(String x){
Connection con;
Statement stmt;
ResultSet rs;
String [] array = new String [2];
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e){
System.out.println("No se pudo lograr la conexion");
}
try{
con = DriverManager.getConnection("jdbc:odbc:con_sql","","");
stmt = con.createStatement();
int z = Integer.parseInt(x);
rs = stmt.executeQuery("SELECT Nombre, Apellido FROM dbo.xxx WHERE ID=" + z);
while(rs.next()){
array[0] = rs.getString("Nombre");
array[1] = rs.getString("Apellido");
Nombre = array[0];
Apellido = array[1];
}
}
catch(Exception e){
System.out.println("Error al seleccionar Empleado" + " "+ e);
}
This method is the one that has to receive the values to put them in a text box.
private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {
String a = txtID.getText();
int x = Integer.parseInt(a);
Conexion c = new Conexion();
txtNombre.setText(c.seleccion(Nombre)); // Does not compile!
txtApellido.setText(c.seleccion(Apellido)); // Does not compile!
}