import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.Vector;
import javax.swing.table.*;
public class Teldirectory {
public Teldirectory () {
JFrame f=new JFrame();
TelTable tt=new TelTable();
JTable table=new JTable(tt);
table.getPreferredScrollableViewportSize(new Dimension(550,30));
JScrollPane e=new JScrollPane(table);
f.getContentPane().add(s,BorderLayout.CENTER);
f.setTitle("µç»°²¾");
f.pack();
f.setVisible(true);
}
}
class TelTable extends AbstractTableModel{ //tableModel
DataBaseManager db=new DataBaseManager();
ResultSet rs;
ResultSetMetaData rsmd;
String strSql="select * from communication";
public int getCol(){ //获取列
rs=db.getResult(strSql);
rsmd=rs.getMetaData();
return rsmd;
}
public int getRow(){ //获取行
rs=db.getResult(strSql);
int i=0;
try{
while(rs.next()){
i++;
}
return i;
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
String[] name={"ID","姓名","手机","电话","QQ"};
String[][] data=new String[getRow()][getCol()];
try{
rs=db.getResult(strSql);
int i=1;
while(rs.next()){
for(int j=0;j<name.length;j++)
data[i][j]=rs.getString(j);
i++;
}
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
public int getColumnCount() {
return name.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return name[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
}
我把程序改成这样,还有两个错误啊,有高手能帮忙看看吗???实现不了想要的结果啊!!很心急了
[此贴子已经被作者于2006-10-30 21:47:21编辑过]