java 访问据库应用实例.docVIP

  • 12
  • 0
  • 约1.03万字
  • 约 6页
  • 2016-10-07 发布于广东
  • 举报
java 访问据库应用实例

实验四 访问数据库应用实例 实验目的: 能够熟练运用某种高级语言进行数据库编程。 实验要求: 根据上次实验所使用的组件,编写一个访问数据库的程序,要求该程序具备查询、插入、删除、修改四个基本功能。 实验过程: 特别声明一下: Java在图形界面设计上,和其他高级语言不太一样。Java都是通过各种类的继承重写和方法的实现达到的。 主窗口完整代码: import java.awt.*; import java.io.*; import java.awt.event.*; public class MainWin{ public static void main(String args[]){ mybutton bn = new mybutton(欢迎使用学生信息查询系统); bn.setSize(250,250);} } class mybutton extends Frame implements ActionListener{ Label l;Button button1,button2,button3,button4,button5; mybutton(String s){ super(s); l = new Label (请按提示选择功能); setLayout(new FlowLayout()); button1 = new Button(查询);add(button1); button2 = new Button(添加);add(button2); button3 = new Button(修改);add(button3); button4 = new Button(删除);add(button4); button5 = new Button(退出);add(button5); button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); button4.addActionListener(this); button5.addActionListener(this); setVisible(true);validate();} public void actionPerformed(ActionEvent e){ if(e.getSource() == button2){ addwin a = new addwin(欢迎使用添加系统); a.setSize(250,250);} else if(e.getSource() == button1){ searchwin s = new searchwin(欢迎使用查询系统); s.setSize(250,300);} else if(e.getSource() == button3){ editwin edit = new editwin(欢迎使用修改系统); edit.setSize(250,250);} else if(e.getSource() == button4){ delwin d = new delwin(欢迎使用删除系统); d.setSize(250,300);} else if(e.getSource() == button5){ System.exit(0);} } } 查询窗口部分代码: try{ con = DriverManager.getConnection(jdbc:odbc:student,high-PC/high,); sql = con.createStatement(); String sno = 0,sname = 0,sdept = 0,editStr ; int sage = 0; if(e.getSource() == b1){ sno = f1.getText(); editStr = SELECT sno,sname,sage,sdept FROM Student WHERE sno = + sno ; rs = sql.executeQuery(editStr); while (rs.next()){ sno = rs.getString(1); sname = rs.getString(2);sa

文档评论(0)

1亿VIP精品文档

相关文档