




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、課程實(shí)驗(yàn)報(bào)告課程名稱(chēng)Java應(yīng)用技術(shù)班級(jí)計(jì)算121實(shí)驗(yàn)日期姓名蔡篤驍學(xué)號(hào)實(shí)驗(yàn)成績(jī)實(shí)驗(yàn)名稱(chēng)實(shí)驗(yàn)5:數(shù)據(jù)庫(kù)應(yīng)用設(shè)計(jì)實(shí)驗(yàn)?zāi)康募耙?掌握如何創(chuàng)建數(shù)據(jù)源;2掌握J(rèn)DBC-ODBC橋接器和JDBC的概念;3掌握查詢(xún)記錄;4掌握更新、添加、刪除記錄。實(shí)驗(yàn)環(huán)境操作系統(tǒng):WindowsIDE:JDK 或者 MyEclipse實(shí)驗(yàn)內(nèi)容(1)學(xué)生信息管理系統(tǒng)。學(xué)生成績(jī)表Student(Sno 字符串,長(zhǎng)度9, Sname 字符串,長(zhǎng)度10, Class 字符串,長(zhǎng)度10, Age 整型, Sex 字符串,長(zhǎng)度2)實(shí)現(xiàn)如下功能,要求用圖形化界面去實(shí)現(xiàn):A輸入若干個(gè)學(xué)生的信息到Student表;B修改制定學(xué)號(hào)學(xué)生的基
2、本信息;C刪除指定學(xué)號(hào)的學(xué)生基本信息;D按照性別找出所有相應(yīng)的學(xué)生基本信息;E按照年齡段找出所有相應(yīng)的學(xué)生基本信息,例如19,21的學(xué)生。調(diào)試過(guò)程及實(shí)驗(yàn)結(jié)果實(shí)驗(yàn)執(zhí)行結(jié)果:運(yùn)行程序,出現(xiàn)界面,確定進(jìn)入,進(jìn)入后進(jìn)行選擇 1、點(diǎn)擊“輸入信息”,出現(xiàn)界面,輸入信息,確定后有提示框 輸入多條信息后在數(shù)據(jù)庫(kù)中打開(kāi)表為:2、點(diǎn)擊“修改信息”, 出現(xiàn)界面,輸入信息,確定后有提示框 修改后打開(kāi)在數(shù)據(jù)庫(kù)中的表為:3、點(diǎn)擊“刪除信息”, 出現(xiàn)界面,輸入刪除學(xué)號(hào),確定后有提示框刪除后打開(kāi)在數(shù)據(jù)庫(kù)中的表為4、對(duì)學(xué)生性別進(jìn)行查找,在數(shù)據(jù)庫(kù)中顯示為:5、對(duì)年齡段進(jìn)行查找,在數(shù)據(jù)庫(kù)中顯示為: 總結(jié)通過(guò)本次試驗(yàn),知道了如何創(chuàng)建
3、數(shù)據(jù)源,和JDBC-ODBC橋接器和JDBC的概念,理解了查詢(xún)記錄和更新、添加、刪除記錄。但是還有許多不足的地方,以后還得要加強(qiáng)這方法的學(xué)習(xí)。附錄import java.sql.*;import javax.swing.JFrame;import java.awt.FlowLayout;import java.awt.GridLayout;import javax.swing.JButton;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JLabel;impor
4、t javax.swing.JPasswordField;import javax.swing.JOptionPane;import javax.swing.JTextField;public class z extends JFrame public String JDriver =com.microsoft.sqlserver.jdbc.SQLServerDriver; public String conURL =jdbc:sqlserver:/localhost:1433;databaseName=test;user=sa;password=123;class Display exten
5、ds JFrame /菜單界面 JButton b1=new JButton(輸入信息);JButton b2=new JButton(修改信息);JButton b3=new JButton(刪除信息);JButton b4=new JButton(按照性別查找學(xué)生信息);JButton b5=new JButton(按照年齡查找學(xué)生信息);JLabel a=new JLabel(請(qǐng)選擇想要進(jìn)行的操作 );Display() super(學(xué)生信息管理系統(tǒng));setSize(500,400);setLocation(400,100); setDefaultCloseOperation(JFra
6、me.EXIT_ON_CLOSE); setLayout(null);b1.setLocation(50,150);b2.setLocation(200,150);b3.setLocation(350,150);b4.setLocation(25,250);b5.setLocation(250,250);a.setLocation(150,50);b1.setSize(100,50);b2.setSize(100,50);b3.setSize(100,50);b4.setSize(200,50);b5.setSize(200,50);a.setSize(500,50);add(b1);add(
7、b2);add(b3);add(b4);add(b5);add(a);listen1(); void listen1() /監(jiān)聽(tīng) b1.addActionListener(new ActionListener()/輸入信息 public void actionPerformed(ActionEvent e )Create a=new Create();a.setVisible(true););b2.addActionListener(new ActionListener() /修改信息 public void actionPerformed(ActionEvent e )Update b=ne
8、w Update();b.setVisible(true););b3.addActionListener(new ActionListener() / 刪除指定學(xué)生信息public void actionPerformed(ActionEvent e )Delete c=new Delete();c.setVisible(true););b4.addActionListener(new ActionListener() /按照性別查找public void actionPerformed(ActionEvent e )Sex d= new Sex();d.setVisible(true););
9、b5.addActionListener(new ActionListener() /按照年齡查找public void actionPerformed(ActionEvent e ) Age f= new Age();f.setVisible(true);); class Create extends JFrame /輸入信息JButton OK=new JButton (確定);JLabel a1=new JLabel(Sno);JLabel a2=new JLabel(Sname);JLabel a3=new JLabel(Class);JLabel a4=new JLabel(Age)
10、;JLabel a5=new JLabel(Sex);JTextField t1=new JTextField(10);JTextField t2=new JTextField(10);JTextField t3=new JTextField(10);JTextField t4=new JTextField(10);JTextField t5=new JTextField(10);Create()super(學(xué)生信息管理系統(tǒng));setSize(300,300);setLocation(400,400);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
11、;setLayout(null);a1.setLocation(0,20);a1.setSize(50,20);t1.setLocation(50,20);t1.setSize(200,20);a2.setLocation(0,40);a2.setSize(50,20);t2.setLocation(50,40);t2.setSize(200,20);a3.setLocation(0,60);a3.setSize(50,20);t3.setLocation(50,60);t3.setSize(200,20);a4.setLocation(0,80);a4.setSize(50,20);t4.s
12、etLocation(50,80);t4.setSize(200,20);a5.setLocation(0,100);a5.setSize(50,20);t5.setLocation(50,100);t5.setSize(200,20);OK.setSize(100,20);OK.setLocation(150,150);add(a1); add(t1);add(a2); add(t2);add(a3); add(t3);add(a4); add(t4);add(a5); add(t5);add(OK); listen2();void listen2()OK.addActionListener
13、(new ActionListener() public void actionPerformed(ActionEvent e )try Class.forName(JDriver); catch (java.lang.ClassNotFoundException f) System.out.println(forname:+f.getMessage();try Connection con =DriverManager.getConnection(conURL); Statement s=con.createStatement(); String CreateTable = create t
14、able Student(Sno char(9), Sname char(10) , Class char(10), Age smallint, Sex char(2); s.executeQuery(CreateTable);s.close();con.close();catch ( SQLException f) System.out.println(SQLException:+f.getMessage();tryConnection con =DriverManager.getConnection(conURL);Statement s=con.createStatement(); St
15、ring find = INSERT INTO Student VALUES( + t1.getText() + , + t2.getText() + , + t3.getText()+ ,+t4.getText()+, + t5.getText() + );PreparedStatement ps=con.prepareStatement(find);ps.executeUpdate(); s.close();con.close();catch ( SQLException f) System.out.println(SQLException:+f.getMessage();String s
16、s=輸入成功!; JOptionPane.showMessageDialog(null, ss););class Update extends JFrame /修改指定學(xué)號(hào)學(xué)生信息 JButton OK=new JButton (確定);JLabel a1=new JLabel(要修改的學(xué)號(hào):);JTextField t1=new JTextField(10);JLabel a2=new JLabel(修改后該學(xué)生姓名為:);JTextField t2=new JTextField(10);JLabel a3=new JLabel(修改后該學(xué)生班級(jí)為:);JTextField t3=new J
17、TextField(10);JLabel a4=new JLabel(修改后該學(xué)生年齡為:);JTextField t4=new JTextField(10);JLabel a5=new JLabel(修改后該學(xué)生性別為:);JTextField t5=new JTextField(10);Update() super(學(xué)生信息管理系統(tǒng));setSize(400,300);setLocation(400,400);setLayout(null);a1.setLocation(0,20);a1.setSize(130,20);t1.setLocation(130,20);t1.setSize(2
18、00,20);a2.setLocation(0,40);a2.setSize(130,20);t2.setLocation(130,40);t2.setSize(200,20);a3.setLocation(0,60);a3.setSize(130,20); t3.setLocation(130,60);t3.setSize(200,20);a4.setLocation(0,80);a4.setSize(130,20); t4.setLocation(130,80);t4.setSize(200,20); a5.setLocation(0,100);a5.setSize(130,20);t5.
19、setLocation(130,100);t5.setSize(200,20);OK.setSize(100,20); OK.setLocation(200,150); add(a1); add(t1); add(a2); add(t2); add(a3); add(t3); add(a4); add(t4); add(a5); add(t5); add(OK); listen3();void listen3() OK.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e )try Cla
20、ss.forName(JDriver);catch (java.lang.ClassNotFoundException f) System.out.println(forname:+f.getMessage();try Connection con =DriverManager.getConnection(conURL); Statement s=con.createStatement(); String find = UPDATE Student SET Sno = + t1.getText() + ,Sname = + t2.getText() + ,Class = + t3.getTex
21、t() + ,Age = + t4.getText() + ,Sex = + t5.getText() + WHERE Student.Sno = + t1.getText() + ;PreparedStatement ps=con.prepareStatement(find); ps.executeUpdate(); s.close();con.close(); catch ( SQLException f) System.out.println(SQLException:+f.getMessage();String ss=修改完成!;JOptionPane.showMessageDialo
22、g(null, ss););class Delete extends JFrame /刪除指定學(xué)號(hào)學(xué)生信息 JButton OK=new JButton (確定);JLabel a=new JLabel(要?jiǎng)h除的學(xué)生學(xué)號(hào):);JTextField t=new JTextField(10);Delete() super(學(xué)生信息管理系統(tǒng)); setSize(300,200);setLocation(400,400);setLayout(null);a.setSize(150,20);a.setLocation(0,50);t.setSize(150,20);t.setLocation(0,70)
23、;OK.setSize(100,20);OK.setLocation(150,100); add(a);add(t); add(OK);listen4();void listen4()OK.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e )try Class.forName(JDriver); catch(java.lang.ClassNotFoundException f) System.out.println(forname:+f.getMessage();try Connect
24、ion con =DriverManager.getConnection(conURL);Statement s=con.createStatement();String find = DELETE FROM Student WHERE Sno = + t.getText() + ;PreparedStatement ps=con.prepareStatement(find);ps.executeUpdate(); s.close(); con.close(); catch ( SQLException f) System.out.println(SQLException:+f.getMess
25、age(); String ss=刪除成功!; JOptionPane.showMessageDialog(null, ss););class Sex extends JFrame /按性別找所有相應(yīng)的學(xué)生信息JLabel a=new JLabel(按性別查找:);JButton b1=new JButton (查找男生的信息);JButton b2=new JButton (查找女生的信息);Sex()super(學(xué)生信息管理系統(tǒng));setSize(300,200);setLocation(400,400);setLayout(null);a.setSize(300,20);a.setLoc
26、ation(0,20);b1.setSize(200,20);b1.setLocation(50,50);b2.setSize(200,20);b2.setLocation(50,100);add(a);add(b1);add(b2); listen51();listen52();void listen51()b1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e )try Class.forName(JDriver); catch (java.lang.ClassNotFoundEx
27、ception f) System.out.println(forname:+f.getMessage();try Connection con =DriverManager.getConnection(conURL);Statement s=con.createStatement();String find = SELECT * FROM Student WHERE Student.Sex = 男; ResultSet rs=s.executeQuery(find);while(rs.next() System.out.println(rs.getString(Sno)+t+rs.getSt
28、ring(Sname)+t+rs.getString(Class)+t+rs.getInt(Age)+t+rs.getString(Sex); s.close(); con.close(); catch ( SQLException f) System.out.println(SQLException:+f.getMessage(); String ss=查找男生的信息成功!; JOptionPane.showMessageDialog(null, ss););void listen52()b2.addActionListener(new ActionListener()public void
29、 actionPerformed(ActionEvent e )try Class.forName(JDriver); catch (java.lang.ClassNotFoundException f) System.out.println(forname:+f.getMessage();try Connection con =DriverManager.getConnection(conURL);Statement s=con.createStatement();String find = SELECT * FROM Student WHERE Student.Sex = 女;Result
30、Set rs=s.executeQuery(find);while(rs.next()System.out.println(rs.getString(Sno)+t+rs.getString(Sname)+t+rs.getString(Class)+t+rs.getInt(Age)+t+rs.getString(Sex); s.close(); con.close(); catch ( SQLException f) System.out.println(SQLException:+f.getMessage();String ss=查找女生的信息成功!;JOptionPane.showMessa
31、geDialog(null, ss););class Age extends JFrame /按年齡查找相應(yīng)的學(xué)生信息JButton OK=new JButton (確定);JLabel a=new JLabel(按年齡段查找: );JTextField t1=new JTextField(3);JButton b2=new JButton (至);JTextField t2=new JTextField(3);Age() super(學(xué)生信息管理系統(tǒng)); setSize(300,150); setLocation(400,400);setLayout(null);a.setSize(300,
32、20);a.setLocation(0,20);b2.setSize(50,20);b2.setLocation(100,50);t1.setSize(50,20);t1.setLocation(50,50);t2.setSize(50,20);t2.setLocation(150,50);OK.setSize(100,20);OK.setLocation(80,80);add(a);add(t1);add(b2);add(t2);add(OK);listen6();void listen6()OK.addActionListener(new ActionListener()public vo
33、id actionPerformed(ActionEvent e ) int n1=Integer.parseInt(t1.getText();int n2=Integer.parseInt(t2.getText();try Class.forName(JDriver); catch (java.lang.ClassNotFoundException f) System.out.println(forname:+f.getMessage();try Connection con =DriverManager.getConnection(conURL);Statement s=con.createStatement();ResultSet rs=s.executeQuery(select * from Student where Age=+
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年智能化柜式或抽屜式斷路器項(xiàng)目發(fā)展計(jì)劃
- 商場(chǎng)管理綜合手冊(cè)
- 二零二五年度新能源合同能源管理項(xiàng)目終止的多重原因解析
- 休閑農(nóng)業(yè)場(chǎng)地暖維修協(xié)議
- 二零二五年度股東退股協(xié)議書(shū):人工智能股權(quán)退出與數(shù)據(jù)倫理規(guī)范合同
- 信息系統(tǒng)監(jiān)理居間合同
- 四年級(jí)數(shù)學(xué)三位數(shù)除以?xún)晌粩?shù)競(jìng)賽練習(xí)題大全附答案
- 汽車(chē)發(fā)動(dòng)機(jī)電控系統(tǒng)診斷與修復(fù)復(fù)習(xí)題與參考答案
- ASP練習(xí)題庫(kù)與參考答案
- 7 我們有新玩法(教學(xué)設(shè)計(jì))-2023-2024學(xué)年統(tǒng)編版道德與法治二年級(jí)下冊(cè)
- 員工聘用合同范本(2024版)
- DL∕T 5161.6-2018 電氣裝置安裝工程質(zhì)量檢驗(yàn)及評(píng)定規(guī)程 第6部分:接地裝置施工質(zhì)量檢驗(yàn)
- 《烏有先生歷險(xiǎn)記》原文及翻譯
- 部編版道德與法治六年級(jí)下冊(cè)課程綱要
- DL-T439-2018火力發(fā)電廠高溫緊固件技術(shù)導(dǎo)則
- 人員測(cè)評(píng)方案
- 簡(jiǎn)易呼吸器的使用和心肺復(fù)蘇-3
- 2024年河北省九地市中考數(shù)學(xué)摸底試卷
- (正式版)JBT 14787-2024 可同步限矩型液力耦合器
- 流行音樂(lè)(中國(guó))
- 《標(biāo)準(zhǔn)字體設(shè)計(jì)》課件
評(píng)論
0/150
提交評(píng)論