Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. DefaultTableModel model=(DefaultTableModel)dbTbl.getModel();
  2. try{
  3. Class.forName("com.mysql.jdbc.Driver");
  4. Connection con=DriverManager.getConnection("jdbc:mysql//localhost/:3306","root","password");
  5. Statement stmt=con.createStatement();
  6. ResultSet rs=stmt.executeQuery("show databases;");
  7. while(rs.next())
  8. {
  9. String db=rs.getString(1);
  10. model.addRow(new Object[] {db});
  11. }
  12. rs.close();
  13. stmt.close();
  14. con.close();
  15. }
  16. catch(Exception e)
  17. {
  18. JOptionPane.showMessageDialog(null,"nahi chalda");
  19. }
  20.  
  21. Class.forName("com.mysql.jdbc.Driver");
  22. Connection con=DriverManager.getConnection("jdbc:mysql://localhost/:3306","root","password");
  23. DatabaseMetaData meta = con.getMetaData();
  24. ResultSet res = meta.getCatalogs();
  25. while (res.next()) {
  26. String db=rs.getString("TABLE_CAT");
  27. model.addRow(new Object[] {db});
  28. }
  29. res.close();
  30.  
  31. Connection con=DriverManager.getConnection("jdbc:mysql://localhost/:3306","root","password");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement