• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please provide me the code....
I don't think anyone will just give you the code.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic