|
-
July 5th, 2005, 09:13 AM
#1
ResultSet and JTable
HI,
am trying to get my data and display it in a JTable, but nothing is showing. No error and no nothing.
I have initialised my JTable with a constructor 'a table model'.
Here's the code
public class FrameView extends JFrame {
.
.
.
MyModel mymodel=new MyModel();
JTable jTable2= new JTable(mymodel);
JScrollPane jScrollPane1 = new JScrollPane(jTable2);
}
class MyModel extends AbstractTableModel{
connecting aconnecting=new connecting();
Statement stmt;
Connection connview;
Vector cache;
int colcount;
String[] headers;
public MyModel(){
cache=new Vector();
}
public String getColumnName(int i) {
return headers[i];
}
public int getColumnCount() {
return colcount;
}
public int getRowCount() {
return cache.size();
}
public Object getValueAt(int row, int col) {
return ((String[]) cache.elementAt(row))[col];
}
public void myfunction(String myyear, String mymonth){
String year, month,query;
year=myyear;
month=mymonth;
try{
this.connview= aconnecting.conn;
aconnecting.connect();
query="SELECT * FROM OPIS";
stmt=connview.createStatement();
ResultSet rs=stmt.executeQuery(query);
ResultSetMetaData meta=rs.getMetaData();
meta.getColumnCount();
//we rebuild the headers array with the new column names
headers=new String[colcount];
for(int h=1;h<=colcount;h++){
headers[h - 1] = meta.getColumnName(h);
}
while(rs.next()){
String[] record=new String[colcount];
for(int i=0;i<colcount;i++){
record[i]=rs.getString(i+1);
}
cache.addElement(record);
}
}
catch(SQLException se){
System.err.print("Error:"+se.getMessage());
cache = new Vector(); // blank it out and keep going.
se.printStackTrace();
}
}
}
It cant work, sb help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|