public class Logica_usuario {
public class Logica_usuario {
private ConexionMySQL MySQL = new ConexionMySQL();
private Connection con = MySQL.conectarMySQL();
private String sSQL = "";
public int totalUsuarios = 0;
public DefaultTableModel buscarRegistro(String buscar) {
DefaultTableModel model;
model = null;
String [] titulosColumnas = {"ID", "Nombre", "Apellido", "Usuario", "Contraseña", "ID Perfil"};
StringObject [][][] registros = new String[6];
modelObject[6][6];//6 =fila newpor DefaultTableModel(null,6 titulosColumnas);columnas
sSQL = "SELECT * FROM usuario WHERE nombre LIKE '%" + buscar + "%' ORDER BY id_usuario";
// Java 7 try-with-resources
try (PreparedStatement pstm = con.prepareStatement(sSQL);
ResultSet rs = pstm.executeQuery(sSQL)) {
int i = 0;
while (rs.next()) {
registros[0]registros[i][0] = rs.getStringgetInt("id_usuario");
registros[1]registros[i][1] = rs.getString("nombre");
registros[2]registros[i][2] = rs.getString("apellido");
registros[3]registros[i][3] = rs.getString("usuario");
registros[4]registros[i][4] = rs.getString("contrasena");
registros[5]registros[i][5] = rs.getStringgetInt("id_perfil");
totalUsuarios++;
i++;
}
model = new model.addRowDefaultTableModel(registros, titulosColumnas);
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "SQLException:\n" + e, "Error: mostrarRegistros(String buscar)", JOptionPane.ERROR_MESSAGE);
}
return model;
}
}
Mi procedimiento en mi clase Ventana_Usuario:
EDIT: agrego StackTrace
StackTrace
java.lang.NullPointerException
at ventanas.Ventana_Usuario.buscarRegistro(Ventana_Usuario.java:66)
at ventanas.Ventana_Usuario.<init>(Ventana_Usuario.java:110)
at ventanas.Ventana_Usuario$1.run(Ventana_Usuario.java:87)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Ventana_Usuario.java:66
table.setModel(model);
Ventana_Usuario.java:110
buscarRegistro("");
Ventana_Usuario.java:87)
Ventana_Usuario frame = new Ventana_Usuario();