It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable" Watch "JTable" New topic


tanvir rony

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.
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="" target="_blank" rel="nofollow"></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
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);
rowData = new String[colCount];
for(int i=0; i<colCount; i++)
rowData = null;
catch(SQLException sqle)
//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
I agree. Here's the link:
subject: JTable
It's not a secret anymore!