Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (txtDniColaborador.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "DEBE INGRESAR UN DNI");
- } else {
- tabla = txtTabla.getText();
- dni = txtDniColaborador.getText();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbDaca?zeroDateTimeBehavior=convertToNull", "root", "1234");
- Statement st = conexion.createStatement();
- ResultSet rst = st.executeQuery("SELECT CONCAT("+tabla+") LIKE '%" + tabla + "%' FROM WHERE CONCAT(DniColaborador) LIKE '%" + dni + "%'");
- ResultSetMetaData rsmt = rst.getMetaData();
- int nrocolumnas = rsmt.getColumnCount();
- DefaultTableModel modelo = new DefaultTableModel();
- this.jTable1.setModel(modelo);
- for (int x = 1; x <= nrocolumnas; x++) {
- modelo.addColumn(rsmt.getColumnLabel(x));
- }
- while (rst.next()) {
- Object[] fila = new Object[nrocolumnas];
- for (int y = 0; y < nrocolumnas; y++) {
- fila[y] = rst.getObject(y + 1);
- }
- modelo.addRow(fila);
- }
- } catch (ClassNotFoundException ce) {
- ce.printStackTrace();
- } catch (SQLException se) {
- se.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment