class Biao extends Frame{
public Biao(){
TextField tf = new TextField("姓名");
tf.setEditable(false);
TextField tf1 = new TextField("性别");
tf1.setEditable(false);
TextField tf2 = new TextField("年龄");
tf2.setEditable(false);
TextField tf3 = new TextField("民族");
tf3.setEditable(false);
TextField tf4 = new TextField("文化程度");
tf4.setEditable(false);
TextField tf5 = new TextField("职名");
tf5.setEditable(false);
TextField tf6 = new TextField("家庭出身");
tf6.setEditable(false);
TextField tf7 = new TextField("本人成分");
tf7.setEditable(false);
add(tf);
add(tf1);
add(tf2);
add(tf3);
add(tf4);
add(tf5);
add(tf6);
add(tf7);
Connection cc = null;
ResultSet re = null;
Statement stat = null;
ResultSet re1 = null;
int num = 0;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");//创建一个驱动
cc = DriverManager.getConnection("jdbcracle:thin192.168.0.5:1521:oracle92","tom","123456789");//获取JDBC链接
HH:
stat = cc.createStatement();//开启向oracle发送语句管道
re1 = stat.executeQuery("SELECT COUNT(*) AS rowcount from renshi");
re1.next();
num = re1.getInt("rowcount");
setLayout(new GridLayout(num+1,8));
num = num*8;
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(re1 != null){
re1.close();//关闭资源
re1 = null;//将变量设为空让垃圾处理器随时回收
}
}catch(SQLException e){
e.printStackTrace();
}
}
try{
stat = cc.createStatement();//开启向oracle发送语句管道
re = stat.executeQuery("select * from renshi");//发送搜索语句
System.out.println(num);
int i = 0 ;
TextField[] ar = new TextField[num];
System.out.println(1);
while(re.next()){//便利取出返回数据
TextField td1 = new TextField(re.getString("姓名"));
TextField td2 = new TextField(re.getString("性别"));
TextField td3 = new TextField(re.getString("年龄"));
TextField td4 = new TextField(re.getString("民族"));
TextField td5 = new TextField(re.getString("文化程度"));
TextField td6 = new TextField(re.getString("职名"));
TextField td7 = new TextField(re.getString("家庭出身"));
TextField td8 = new TextField(re.getString("本人成分"));
ar[i] = td1;
ar[i+1]= td2;
ar[i+2]= td3;
ar[i+3]= td4;
ar[i+4]= td5;
ar[i+5]= td6;
ar[i+6]= td7;
ar[i+7]= td8;
i=i+8;
}
int aa=0;
int x =1;
while(aa != ar.length){
int t = ar.length;
System.out.println("t="+t);
System.out.println("aa="+aa);
add(ar[aa]);
aa++;
System.out.println(x);
x++;
}
}catch(SQLException e){
e.printStackTrace();
}
finally{
try{
if(re != null){
re.close();//关闭资源
re = null;//将变量设为空让垃圾处理器随时回收
}
if(stat != null){
stat.close();
stat = null;
}
if(cc != null){
cc.close();
cc = null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
MenuBar m = new MenuBar();
Menu me = new Menu("文件");
Menu me1 = new Menu("编辑");
MenuItem mi = new MenuItem("打开");
MenuItem mi1 = new MenuItem("保存");
MenuItem mi2 = new MenuItem("添加");
mi2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try {
Shenhe sh = new Shenhe();
break HH;
} catch (SexException e1) {
e1.printStackTrace();
}
}
});
MenuItem mi3 = new MenuItem("退出");
mi3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
MenuItem mi4 = new MenuItem("复制");
MenuItem mi5 = new MenuItem("搜索");
mi5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
SouSou s = new SouSou();
}
});
me.add(mi);
me.add(mi1);
me.add(mi2);
me.add(mi3);
me1.add(mi4);
me1.add(mi5);
m.add(me);
m.add(me1);
setMenuBar(m);
setSize(650,750);
setLocation(300,0);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
pack();
setVisible(true);
}
}
菜鸟求教!!!!!
|