jtable与数据库查询中的数据不能显示
import java.awt.*;import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.table.DefaultTableModel;
class BookFrame extends JFrame
{
String SQLstatement="select *from BOOK";
Vector rowvector=new Vector(1,1);
DefaultTableModel model=new DefaultTableModel();
JTable table=new JTable(model);
Container contentPane= getContentPane();
public BookFrame()
{
setTitle("图书室书籍信息");
setSize(500,500);
ShowData(SQLstatement);
Container contentPane= getContentPane();
contentPane.add(table);
setVisible(true);
}
public DefaultTableModel ShowData(String sqlstatement)
{
String s="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://xinzhanf-119743:1433;DatabaseName=xinzhanfu";
Connection con=null;
Statement sta=null;
ResultSet rs=null;
try
{
Class.forName(s);
con=DriverManager.getConnection(url,"sa","sa");
sta=con.createStatement();
rs=sta.executeQuery(sqlstatement);
ResultSetMetaData rsmd=rs.getMetaData();
while(rs.next()){
for(int i=1;i<=rsmd.getColumnCount();i++)
{
System.out.println(rs.getString(i));
rowvector.add(rs.getString(i));
model.addColumn(rowvector);
}
}
}
catch(Exception e)
{
System.out.println(e);
}
return model;
}
public static void main(String args[])
{
BookFrame bookframe=new BookFrame();
bookframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
bookframe.show();
}
}
为什么没有table,
只是一个空的页面,没有任何数据啊!
private DefaultTableModel model;