java - JTable swing import database sql -
could provide me example or tutorial on how import data mysql database within jtable within use of gui. tried looking example have not found anything.
hopefully can put question rest
connection db = drivermanager.getconnection( jdbc:mysql://192.168.0.3:3306,<user>,<password>); statement stmt = db.createstatement(); preparedstatement psmt = con.preparestatement("select * db"); resultset rs = psmt.executequery(); // column names int len = rs.getmetadata().getcolumncount(); vector cols= new vector(len); for(int i=1; i<=len; i++) // note starting @ 1 cols.add(rs.getmetadata().getcolumnname(i)); // add data vector data = new vector(); while(rs.next()) { vector row; = new vector(len); for(int i=1; i<=len; i++) { row.add(rs.getstring(i)); } data.add(row); } // create table jtable table = new jtable(data, cols);
Comments
Post a Comment