Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public void cargarGrilla(){
  2. try{
  3. Class.forName("com.mysql.jdbc.Driver");
  4. Connection con = DriverManager.getConnection(
  5. "jdbc:mysql://localhost/biblioteca","root","1234");
  6. Statement comando = con.createStatement();
  7. ResultSet resultado = comando.executeQuery(
  8. "select * from libros");
  9. DefaultTableModel datos =
  10. (DefaultTableModel) jTable1.getModel();
  11. datos.setRowCount(0);
  12. while(resultado.next()){
  13. String[] fila = {
  14. resultado.getString("codigo"),
  15. resultado.getString("nombre"),
  16. resultado.getString("genero")
  17. };
  18. datos.addRow(fila);
  19. }
  20.  
  21. } catch(Exception e){
  22. System.out.println(e);
  23. }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement