| Author |
JTable
|
tanvir rony
Greenhorn
Joined: Feb 07, 2002
Posts: 3
|
|
i use JTable in front end(AbstractTableModel). Oracle in the back end. i pass data through a form to the database, i want to retrive and show data in the JTable which is in my that form. please provide me the code. thanks.
|
 |
Sayed Ibrahim Hashimi
Ranch Hand
Joined: May 17, 2001
Posts: 148
|
|
please provide me the code.... I don't think anyone will just give you the code.
|
SCJP 1.4<br /><a href="http://www.cise.ufl.edu/~sih" target="_blank" rel="nofollow">www.cise.ufl.edu/~sih</a>
|
 |
Serghei Jelauc
Ranch Hand
Joined: Jul 24, 2002
Posts: 128
|
|
If you have connected to your database, you may create JTable as follow: class myModel extends AbstractTableModel { String []colNames; String []rowData; int colCount; Vector data = new Vector(); //You have to pass in this class Statement //object of your connection Statement stmt; public myModel(Statement stmt) { this.stmt = stmt; //You mast create ResultSet and //ResultSetMetaData object for //receiving datas from your table try { ResultSet rs = stmt.exequteQuery ("Selct * from myTable"); ResultSetMetaData rsmd = rs.getMetaData(); colCount = rsmd.getColumnCount(); colNames = new String[colCount]; for(int i=0; i<colCount; i++) { colNames[i] = rsmd.getColumnName(i); } while(rs.next()) { rowData = new String[colCount]; for(int i=0; i<colCount; i++) { rowData[i]=rs.getString(i+1); } data.add(rowData); rowData = null; } } catch(SQLException sqle) {System.out.println(sqle.getMessage());} } //Now you must overload methods from // AbstactTableModel public int getColumnCount() {return colCount;} public String getColumnName(int col) {return colNames[col];} public int getRowCount() {return data.size();} public Object getValueAt(int row, int col) {return ((String[])(data.elementAt(row)))[col];} } That's all. Now in your application you may create an object of myModel type, and when you will create a JTable object, you will pass it myMidel object as argument. I hope it will help You and sorry for my English;
|
SCJP 1.4 <br />SCBCD 1.3<br />SCWCD 1.4
|
 |
 |
|
|
subject: JTable
|
|
|