网站大量收购独家精品文档,联系QQ:2885784924

java访问数据库应用实例.doc

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实验四 访问数据库应用实例 实验目的: 能够熟练运用某种高级语言进行数据库编程。 实验要求: 根据上次实验所使用的组件,编写一个访问数据库的程序,要求该程序具备查询、插入、删除、修改四个基本功能。 实验过程: 特别声明一下: 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)

185****7617 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档