Guest User

Untitled

a guest
Mar 18th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. if (txtDniColaborador.getText().isEmpty()) {
  2. JOptionPane.showMessageDialog(null, "DEBE INGRESAR UN DNI");
  3. } else {
  4.  
  5. tabla = txtTabla.getText();
  6. dni = txtDniColaborador.getText();
  7. try {
  8. Class.forName("com.mysql.jdbc.Driver");
  9.  
  10. Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbDaca?zeroDateTimeBehavior=convertToNull", "root", "1234");
  11. Statement st = conexion.createStatement();
  12. ResultSet rst = st.executeQuery("SELECT CONCAT("+tabla+") LIKE '%" + tabla + "%' FROM WHERE CONCAT(DniColaborador) LIKE '%" + dni + "%'");
  13. ResultSetMetaData rsmt = rst.getMetaData();
  14. int nrocolumnas = rsmt.getColumnCount();
  15. DefaultTableModel modelo = new DefaultTableModel();
  16. this.jTable1.setModel(modelo);
  17. for (int x = 1; x <= nrocolumnas; x++) {
  18. modelo.addColumn(rsmt.getColumnLabel(x));
  19.  
  20. }
  21.  
  22. while (rst.next()) {
  23. Object[] fila = new Object[nrocolumnas];
  24.  
  25. for (int y = 0; y < nrocolumnas; y++) {
  26. fila[y] = rst.getObject(y + 1);
  27.  
  28. }
  29.  
  30. modelo.addRow(fila);
  31.  
  32. }
  33.  
  34. } catch (ClassNotFoundException ce) {
  35. ce.printStackTrace();
  36. } catch (SQLException se) {
  37.  
  38. se.printStackTrace();
  39. }
  40. }
Add Comment
Please, Sign In to add comment