用Java编写的图形用户界面通讯录packagemyaddressbody;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.Date;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;importjavax.swing.JButton;publicclassDemonstrationacctionimplementsActionListener{ publicvoidactionPerformed(ActionEvente){ if(((JButton)e.getSource()).getText().equals("显示查询结果")){ Stringdburl="jdbc:odbc:driver={MicrosoftAccessDriver(*.mdb)};DBQ=main.mdb"; Stringsql; Connectioncon; Statementstmt; Stringnm,sx,mp,ph,em,ca,ha,nb,gp,lbMQ,all; booleanbdr; Datebd; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }catch(java.lang.ClassNotFoundExceptione2){ System.err.print("ClassNotFoundException:"); System.err.println(e2.getMessage()); } try{ con=DriverManager.getConnection(dburl,"",""); stmt=con.createStatement(); sql="SELECT*FROMaddress"; ResultSetws=stmt.executeQuery(sql); while(ws.next()){ nm=ws.getString(1); sx=ws.getString(2); bd=ws.getDate(3); mp=ws.getString(4); ph=ws.getString(5); ca=ws.getString(6); em=ws.getString(7); ha=ws.getString(8); gp=ws.getString(9); nb=ws.getString(10); lbMQ=ws.getString(11); all="姓名:"+nm+"性别:"+sx+"生日:"+bd +"移动电话:"+mp+"固定电话:"+ph+"MSN/QQ:" +lbMQ+"公司地址:"+ca+"EMail:"+em +"家庭地址:"+ha+"组别"+gp+"备注:"+nb +"\n"; Demonstrationaframe.lbdem.append(all); } stmt.close(); con.close(); }catch(Exceptionex) { System.out.println("Exception:"+ex.getMessage()); } } if(((JButton)e.getSource()).getText().equals("退出全部查询")){ Demonstrationaframe.lbdem.setText(""); Demonstrationaframe.demFrame.setVisible(false); } }}
1