I would like to obtain a messageDialog if the id which im filtering is not in the tablemodel i created. the problem is that the ccode works fine without the if, however when i add the if for the messageDialog condition, i realize that the data is found but not shown.
Compare http://prntscr.com/o0z7kqCompare
Code:
public void buscarNumeroSerie (String nserie)
{
try {
String [] campos={"NUMERO_SERIE","MARCA","GAVETA"};
String filtroNS = nserie;
String NSSQL = "SELECT NUMERO_SERIE,MARCA,GAVETA FROM"
+ "(SELECT NUMERO_SERIE,MARCA,GAVETA FROM discos_wd "
+ "UNION "
+ "SELECT NUMERO_SERIE,MARCA,GAVETA FROM discos_toshiba "
+ "UNION "
+ "SELECT NUMERO_SERIE,MARCA,GAVETA FROM discos_seagate "
+ "UNION "
+ "SELECT NUMERO_SERIE,MARCA,GAVETA FROM discos_samsung "
+ "UNION "
+ "SELECT NUMERO_SERIE,MARCA,GAVETA FROM discos_hitachi )"
+ "AS TROUBLE WHERE NUMERO_SERIE LIKE '%"+filtroNS+"%'";
System.out.println(NSSQL);
nsconn = metodosPool.dataSource.getConnection();
ModeloTablaLista = new DefaultTableModel(null, campos);
stmnt = nsconn.prepareStatement(NSSQL);
ResultSet nsrs = stmnt.executeQuery(NSSQL);
if(nsrs.next()== true){
String [] nsfila = new String[3];
while (nsrs.next())
{
nsfila[0]=nsrs.getString("Numero_Serie");
nsfila[1]=nsrs.getString("Marca");
nsfila[2]=nsrs.getString("Gaveta");
ModeloTablaLista.addRow(nsfila);
}
nsrs.close();
stmnt.close();
tablaDiscosGaveta.setModel(ModeloTablaLista);
}
else
{
System.err.println("No existen datos asociados");
JOptionPane.showMessageDialog(rootPane, "Disco no encontrado, quiere:");
}
My idea is that the left image, that which contains the if bit of code show the results i need just like the image on the right. I've tried with "for" sentences, add a new resultSet and change the postion of the if condition without results.
Aucun commentaire:
Enregistrer un commentaire