文档详情

Java语言程序设计 工业和信息化普通高等教育“十二五”规划教材 教学课件 作者 相洁 呼克佑 第12章 JDBC访问数据库.ppt

发布:2017-08-16约2.26万字共73页下载文档
文本预览下载声明
12.3 综合应用举例 图12-17 学生信息查询界面 12.3 综合应用举例 【例12-7】学生信息查询 学生信息查询界面如图12-17所示。相应的类为EX12_7_StudentQuery,文件名为EX12_7_StudentQuery.java。 import java.sql.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.border.*; import javax.swing.JOptionPane; public class EX12_7_StudentQuery extends JPanel implements ActionListener{ Connection con; Statement sql; JTextField t1,t2,t3,t4,t5,t6; JButton b; Box baseBox,bv1,bv2; int flag=0; 12.3 综合应用举例 EX12_7_StudentQuery(){ try{ Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); } catch(ClassNotFoundException e){} try{ con=DriverManager.getConnection(jdbc:odbc:student,,); sql=con.createStatement(); } catch(SQLException ee){} setLayout(new BorderLayout()); b=new JButton(查询); b.setBackground(Color.orange); b.addActionListener(this); 12.3 综合应用举例 t1=new JTextField(8); t2=new JTextField(16); t3=new JTextField(16); t4=new JTextField(16); t5=new JTextField(16); t6=new JTextField(16); t2.setEditable(false); t3.setEditable(false); t4.setEditable(false); t5.setEditable(false); t6.setEditable(false); JPanel p1=new JPanel(),p2=new JPanel(); p1.add(new Label(请输入学号:)); p1.add(t1); p1.add(b); 12.3 综合应用举例 bv1=Box.createVerticalBox(); bv1.add(new JLabel(姓名)); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel(性别)); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel(地址)); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel(电话)); bv1.add(Box.createVerticalStrut(8)); bv1.add(new JLabel(专业)); bv1.add(Box.createVerticalStrut(8)); bv2=Box.createVerticalBox(); bv2.add(t2); bv2.add(Box.createVerticalStrut(8)); bv2.add(t3); 12.3 综合应用举例 bv2.add(Box.createVerticalStrut(8)); bv2.add(t4); bv2.add(Box.createVerticalStrut(8)); bv2.add(t5); bv2.add(Box.createVerticalStrut(8)); bv2.add(t6); bv2.add(Box.createVerticalStrut(8));
显示全部
相似文档