package 我的数据;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.sql.*;
public class peijie extends JFrame {
JPanel contentPane;
JScrollPane jScrollPane1 = new JScrollPane();
Vector data = new Vector();
Vector header = new Vector();
JTable jTable1;
public peijie()
{
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public static void main(String[] args)
{
peijie p=new peijie();
p.setSize(550,400);
p.show();
}
private void jbInit() throws Exception
{
header.add("编号");
header.add("姓名");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception ex)
{
ex.printStackTrace();
}
try
{
Connection conn = DriverManager.getConnection("jdbc:odbc:text");
PreparedStatement st=conn.prepareStatement
("select * from authors where au_lname=?");
st.setString(1,"Green"); //冰哥这个1是意思呀???呵呵帮我解释一下啊!
ResultSet rs= st.executeQuery();
while (rs.next())
{
Vector v=new Vector();
v.add(rs.getString(1));
v.add(rs.getString(2));
data.add(v);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
jTable1 = new JTable(data,header);
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(473, 317));
setTitle("Frame Title");
jScrollPane1.setBounds(new Rectangle(52, 34, 308, 220));
contentPane.add(jScrollPane1);
jScrollPane1.getViewport().add(jTable1);
}
}