Advertisement
Guest User

Untitled

a guest
Dec 21st, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.*;
  3. import javax.swing.table.DefaultTableModel;
  4. import javax.swing.table.DefaultTableCellRenderer;
  5. import javax.swing.*;
  6. import java.awt.*;
  7. import java.awt.event.*;
  8.  
  9. class BurgerData extends JFrame
  10. {
  11. JTable BurgerList;
  12.  
  13. public BurgerData()
  14. {
  15. setSize(800,800);
  16. setLayout(new FlowLayout());
  17. setVisible(true);
  18. try
  19. {
  20. Class.forName("com.mysql.jdbc.Driver");
  21. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/image","root","");
  22. Statement stmnt = con.createStatement();
  23. ResultSet rs = stmnt.executeQuery("SELECT * FROM `icon`");
  24.  
  25. ResultSetMetaData rsmetadata = rs.getMetaData();
  26. int col = rsmetadata.getColumnCount();
  27. DefaultTableModel dtm = new DefaultTableModel();
  28.  
  29. Vector<String> col_name = new Vector<String>();
  30. Vector<Object> row_data = new Vector<Object>();
  31.  
  32. for(int i=1;i<=col;i++)
  33. {
  34. col_name.addElement(rsmetadata.getColumnName(i));
  35. }
  36.  
  37. dtm.setColumnIdentifiers(col_name);
  38.  
  39. while(rs.next())
  40. {
  41. row_data = new Vector<Object>();
  42.  
  43. for(int i=1;i<=col;i++)
  44. {
  45. row_data.addElement(rs.getObject(i));
  46. }
  47.  
  48. dtm.addRow(row_data);
  49. }
  50.  
  51. BurgerList = new JTable( dtm )
  52. {
  53. public Class getColumnClass(int column)
  54. {
  55. return getValueAt(0, column).getClass();
  56. }
  57. };
  58.  
  59. BurgerList.setModel(dtm);
  60.  
  61. add(BurgerList);
  62.  
  63. }
  64.  
  65. catch(SQLException e)
  66. {
  67. System.out.println("Unknown Error");
  68. }
  69.  
  70. catch(Exception eg)
  71. {
  72. System.out.println("Unknown Error");
  73. }
  74. }
  75.  
  76. public static void main(String args[])
  77. {
  78. BurgerData n = new BurgerData();
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement