When including the SQL variable declared as String. The arrangement does not take it tells me that the tpyes are incompatible. I appreciate your help and explanation.
Conexion cc=new Conexion();
Connection cn= cc.Conexion();
//creamos los titulos a traves de un array
String SQL="";
SQL ="select * from tbl_clientes";
String[] titulos = {"Id","Nombre","Apellido","Genero","Estado","Correo","Teléfono"};
String[] registros = new String[6];
//con esto crearemos la nueva tabla
DefaultTableModel modelo= new DefaultTableModel(null,titulos);
//realizaremos la consulta que traera los datos
SQL ="select * from tbl_clientes";
System.out.println(SQL);
try{
Statement st=cn.createStatement();
ResultSet rs= st.executeQuery(SQL);
//Condición que va recorriendo el arreglo previamente creado.
while (rs.next()){
registros[0] = rs.getString["id_cliente"]
registros[1] = rs.getString["nombre"];
registros[2] = rs.getString["apellido"];
registros[3] = rs.getString["genero"];
registros[4] = rs.getString["estadocivil"];
registros[5] = rs.getString["correo"];
registros[6] = rs.getString["telefono"];
modelo.addRow(registros);
}
tablaPersonas.setModel(modelo);
}catch (Exception e){
JOptionPane.showMessageDialog(null, "Error al mostrar datos"+e.getMessage());
}
}
I don't know what could be generating the error. I thank you again for your collaboration.
You are using the wrong
getString()
object'srs
.Correct it like this:
Note that it
getString()
is a method and like all methods, it must be called using parentheses()
, not[]
.