SHARE
TWEET

Untitled

a guest Jun 26th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void init_table(JTable X)
  2. {
  3. try
  4. {
  5.     Class.forName(JDBC_DRIVER);
  6.     con= DriverManager.getConnection("jdbc:mysql://localhost:3306/store",DB_USER, DB_PASS);
  7.     query="SELECT * from Stalk";
  8.     stmt = con.createStatement();
  9.     rs = stmt.executeQuery(query);
  10.     DefaultTableModel model= new DefaultTableModel();
  11.     ResultSetMetaData meta = rs.getMetaData();
  12.     int Columncount = meta.getColumnCount();
  13.     for(int columnindex=1; columnindex<=Columncount; columnindex++)
  14.     {
  15.         model.addColumn(meta.getColumnLabel(columnindex));
  16.     }
  17.     Object[] row= new Object[Columncount];
  18.     while(rs.next())
  19.     {
  20.     int i=0;
  21.     for(i=0;i<Columncount;i++)
  22.     {
  23.         row[i]=rs.getObject(i+1);
  24.     }
  25.  
  26.     model.addRow(row);
  27.         }
  28.     X.setModel(model);
  29.         }
  30.     catch(Exception e)
  31.     {
  32.         e.printStackTrace();
  33.     }
  34.  
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top