Consult As
Consult As
Alexander Morán
Informática 8B
Programación VIII
MSc. Víctor Zapata
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jTabbedPane1.addTab("Registro", jPanel3);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"id", "Nombre", "Apellido", "Cedula", "Correo"
}
));
jScrollPane1.setViewportView(jTable1);
jTabbedPane1.addTab("Consulta", jPanel2);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jPanel4.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 250, 130, 30));
jLabel1.setText("INGRESE EL NOMBRE");
jPanel4.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 230, -1, -1));
jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jTabbedPane1.addTab("Reportes", jPanel5);
try {
DefaultTableModel modelo = new DefaultTableModel();
jTable1.setModel(modelo);
PreparedStatement ps = null;
ResultSet rs = null;
conectar cc= new conectar();
Connection cn= cc.conexion();
String sql = "SELECT id,Nombre,Apellido,Cedula,Correo FROM usuario ";
ps = cn.prepareStatement(sql);
rs = ps.executeQuery();
ResultSetMetaData rsMd = (ResultSetMetaData) rs.getMetaData();
int cantidadColumnas = rsMd.getColumnCount();
modelo.addColumn("id");
modelo.addColumn("Nombre");
modelo.addColumn("Apellido");
modelo.addColumn("Cedula");
modelo.addColumn("Correo");
while (rs.next()) {
Object[] filas = new Object[cantidadColumnas];
for (int i = 0; i < cantidadColumnas; i++) {
filas[i] = rs.getObject(i + 1);
}
modelo.addRow(filas);
}
try {
DefaultTableModel modelo = new DefaultTableModel();
jTable2.setModel(modelo);
PreparedStatement ps = null;
ResultSet rs = null;
conectar cc= new conectar();
Connection cn= cc.conexion();
String sql = "SELECT id, Nombre, Apellido, Cedula,Correo FROM usuario " + where;
System.out.println(sql);
ps = cn.prepareStatement(sql);
rs = ps.executeQuery();
modelo.addColumn("id");
modelo.addColumn("Nombre");
modelo.addColumn("Apellido");
modelo.addColumn("Cedula");
modelo.addColumn("Correo");
int[] anchos = {50, 100,100,100, 100, 200};
for (int i = 0; i < jTable2.getColumnCount(); i++) {
jTable2.getColumnModel().getColumn(i).setPreferredWidth(anchos[i]);
}
while (rs.next()) {
Object[] filas = new Object[cantidadColumnas];
for (int i = 0; i < cantidadColumnas; i++) {
filas[i] = rs.getObject(i + 1);
}
modelo.addRow(filas);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(panel.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(panel.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(panel.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(panel.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>