import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTable;
public class table extends JFrame implements ActionListener{
Object a[][];
Object b[]={"name","password"};
Container con;
JButton button;
String name,password;
public table(){
a=new Object[30][2];
JTable table=new JTable(a,b);
table.setSize(300,300);
button=new JButton("chaxun");
button.addActionListener(this);
con=getContentPane();
con.add(table,BorderLayout.CENTER);
con.add(button,BorderLayout.SOUTH);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
// TODO 自动生成方法存根
if(e.getSource()==button){
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=gxc";
String user="sa";
String password="sa";
Statement stmt=null;
ResultSet result=null;
Connection dbConn =null;
int i=0;
try {
Class.forName(driverName);
} catch (ClassNotFoundException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
try {
dbConn = DriverManager.getConnection(url, user, password);
stmt=dbConn.createStatement();
String sql="select * from b1";
result =stmt.executeQuery(sql);
while(result.next())
{
name=result.getString(1);
password=result.getString(2);
a[i][0]=name;
a[i][1]=password;
i++;
}
repaint();
dbConn.close();
} catch (SQLException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
}
}
public static void main(String para[]){
table table=new table();
}
}
posted on 2007-07-16 12:46
lcgxc 阅读(300)
评论(0) 编辑 收藏 所属分类:
java