版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、天津理工大學(xué)實(shí)驗(yàn)報(bào)ZE告學(xué)院(系)名稱: 計(jì)算機(jī)與通信工程學(xué)院姓名晴小天學(xué)號(hào)201356XXXX專業(yè)計(jì)算機(jī)科學(xué)與技術(shù)班級(jí)2013級(jí)2班實(shí)驗(yàn)項(xiàng)目實(shí)驗(yàn)五:小型信息管理系統(tǒng)設(shè)計(jì)開發(fā)批改意見課程名稱實(shí)驗(yàn)時(shí)間Java語言程序設(shè)計(jì)2015年11月12日、20日、25日第3、4節(jié)課程代碼實(shí)驗(yàn)地點(diǎn)成績06670567-219教師簽字:實(shí)驗(yàn)內(nèi)容:1.參考實(shí)驗(yàn)資料,自擬題目,設(shè)計(jì)制作一個(gè)小型信息管理系統(tǒng)。實(shí)驗(yàn)?zāi)康?1 .理解并掌握J(rèn)ava數(shù)據(jù)庫訪問技術(shù)。2 .掌握對(duì)數(shù)據(jù)進(jìn)行增加、刪除、修改、查詢。實(shí)驗(yàn)要求:1 .按照要求編制程序;3 .為增加程序可讀性,請(qǐng)?jiān)诔绦蛑袑?duì)類成員進(jìn)行適當(dāng)注釋說明;4 .整理上機(jī)步驟,總結(jié)
2、經(jīng)驗(yàn)和體會(huì);5 .認(rèn)真完成并按時(shí)提交實(shí)驗(yàn)報(bào)告。【實(shí)驗(yàn)過程記錄(源程序、測試用例、測試結(jié)果及心得體會(huì)等)】MIS系統(tǒng)系統(tǒng)名稱:學(xué)生信息管理系統(tǒng)操作系統(tǒng):Window8.1Java 環(huán)境;、jre 1.7.0_21集成開發(fā)環(huán)境:MyEcI ip se P rofessio nal 2013數(shù)據(jù)庫軟件版本: SQL Server 2010連接驅(qū)動(dòng):jdbc-odbc系統(tǒng)主要功能本項(xiàng)目主要實(shí)現(xiàn)了java界面的登錄功能,以及登陸后的增刪改查功能,主要是對(duì)student表實(shí)現(xiàn)增加一條學(xué)生信息、刪除一條學(xué)生信息記錄、更新學(xué)生信息表,以及查詢學(xué)生信息表的數(shù)據(jù)添加刪除更新查找1.2.數(shù)據(jù)庫結(jié)構(gòu)四、關(guān)鍵功能界面截
3、圖數(shù)據(jù)庫名稱:SchoolDB數(shù)據(jù)表:student表具體字段信息如下表:字段名類型長度小數(shù)點(diǎn)不是nullsn ame主鍵)varchar200Vsn amevarchar200Vsde ptvarchar200Vsgradevarchar200Vsaddressvarchar200Vsname, sname, sdept, sgrade 、saddress 分別保存學(xué)生的姓名、專業(yè)、學(xué)院、成績、家庭住址等 學(xué)生基本信息,其中sname為主鍵且不為空。1.登陸界面用戶輸入數(shù)據(jù)庫中存在的用戶名和密碼后,便可登陸成功,否則提示密碼錯(cuò)誤正確的用戶名,錯(cuò)誤的密碼2.正確的用戶名正確的密碼后進(jìn)入學(xué)生信息
4、管理系統(tǒng):添加功能:輸入界面中的所有數(shù)據(jù)之后,點(diǎn)擊添加,即可向數(shù)據(jù)庫中加入一條學(xué)生記錄3. 刪除功能:輸入姓名,即可把數(shù)據(jù)庫中對(duì)應(yīng)姓名的一條學(xué)生信息刪除4. 更新功能:輸入要修改學(xué)生的信息,即可修改該學(xué)生在數(shù)據(jù)庫中的記錄5. 查找功能:點(diǎn)擊查找可以查詢數(shù)據(jù)庫中的所有學(xué)生信息,每頁9條記錄,其余的學(xué)生信息的點(diǎn)擊下一頁,可以查看,還可以點(diǎn)擊上一頁,來切換數(shù)據(jù)點(diǎn)擊下一頁:五、關(guān)鍵代碼分析DBConnetion用于連接數(shù)據(jù)庫:P ackage edu;p ublic class DBConn ecti on p ublic static Conn ecti on getC onn ecti on()C
5、onn ecti on conn = n ull;Stri ng url = "jdbc:odbc:schoolData"Stri ng user name = "sa"Stri ng p assword = "123456"try Class.forName(driver);conn = DriverMa nager.getC onn ectio n(url,username, password); catch (ClassNotFou ndExce pti on e) e.prin tStackTrace(); catch (SQ
6、LExce ption e) e.prin tStackTrace();retur n conn; 登陸的窗體類 LoginFrame 、 JFrame: package edu;LoginFrame frame;JLabel lname;JLabel lpassword; JTextField tname; JPasswordField tpassword; JButton byes;JButton bno;JPanel p1;JPanel p2;JPanel p3;public class Jswing implements ActionListener private private p
7、rivate private private private private private private privateprivate String userName,password;/* 初始化窗口數(shù)據(jù)*/public void initData() frame=new LoginFrame(" 登陸 "); frame.setResizable(false); frame.setLayout(new GridLayout(3, 2); Container c=frame.getContentPane(); lname=new JLabel(" 用戶名:
8、"); lpassword=new JLabel(" 密 碼 : "); tname=new JTextField(8); tpassword=new JPasswordField(8); byes=new JButton(" 確定 "); bno=new JButton(" 取消 "); p1=new JPanel(); p2=new JPanel(); p3=new JPanel(); p1.add(lname); p1.add(tname); c.add(p1);p2.add(lpassword); p2.add(tp
9、assword); c.add(p2);p3.add(byes); p3.add(bno); c.add(p3); frame.setVisible(true); byes.addActionListener(this); bno.addActionListener(this);userName=null;password=null;Overridepublic void actionPerformed(ActionEvent e) if(e.getSource()=bno)System.exit(1);elseif(e.getSource()=byes)userName=tname.getT
10、ext().trim();password=new String(tpassword.getPassword(); boolean result=false;result=SchoolOperate.login(userName, password); if(result)frame.setVisible(false);SwingUtilities.invokeLater(new Runnable() public void run() SchoolInfoGui application = new SchoolInfoGui(); application.getJFrame().setVis
11、ible(true););elseString error=null;if(result=false)H.error=" 用戶名或密碼錯(cuò)誤,請(qǐng)重試! JOptionPane.showMessageDialog(null, error);public static void main(String args) new Jswing().initData();package edu;public class LoginFrame extends JFramepublic LoginFrame(String title) throws HeadlessException super();s
12、etTitle(title);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(540,200, 280, 200);學(xué)生信息管理系統(tǒng)主界面的 SchoolInfoGui package edu;public class SchoolInfoGui implements ActionListener private JFrame jFrame;private JPanel jContentPane;private JLabel lblName = null;private JTextField tfName = null;priv
13、ate JLabel lblRegion = null;private JComboBox cbRegion = null;private JLabel lblArea = null;private JTextField tfArea = null;private JLabel lblPopu = null;private JTextField tfPopu = null;private JLabel lblGdp = null;private JTextField tfGDP = null;private JButton btnAdd = null;private JButton btnDe
14、l = null;private JButton btnModify = null;private JButton btnQuery = null;private JButton btnUpPage = null;private JButton btnDownPage = null; private JTable table = null;TableModel tm = null;JScrollPane jsp = null;private JTextField getTfName() if (tfName = null) tfName = new JTextField();tfName.se
15、tBounds(new Rectangle(89, 17, 173, 27);return tfName;private JComboBox getCbRegion() if (cbRegion = null) String str = " 請(qǐng)選擇 ", " 計(jì)算機(jī)科學(xué)與技術(shù) ", " 信息安全 ", " 網(wǎng)絡(luò)工程 ", " 信息與計(jì)算科學(xué) ", " 物流工程 ", " 軟件工程 "cbRegion = new JComboBox(str);cbRegio
16、n.setBounds(new Rectangle(360, 17, 229, 28);return cbRegion;private JTextField getTfArea() if (tfArea = null) tfArea = new JTextField();tfArea.setBounds(new Rectangle(89, 61, 173, 27);return tfArea; private JTextField getTfPopu() if (tfPopu = null) tfPopu = new JTextField(); tfPopu.setBounds(new Rec
17、tangle(360, 61, 229, 28); return tfPopu; private JTextField getTfGDP() if (tfGDP = null) tfGDP = new JTextField(); tfGDP.setBounds(new Rectangle(89, 105, 173, 27); return tfGDP;private JButton getBtnAdd() if (btnAdd = null) btnAdd = new JButton();btnAdd.setBounds(new Rectangle(46, 152, 71, 30); btnA
18、dd.addActionListener(this);btnAdd.setText(" 添加 ");return btnAdd;private JButton getBtnUpPage() if (btnUpPage = null) btnUpPage = new JButton(" 上一頁 "); btnUpPage.addActionListener(this); btnUpPage.setBounds(200, 390, 80, 30);return btnUpPage;private JButton getBtnDownPage() if (bt
19、nDownPage = null) btnDownPage = new JButton("下一頁 ");btnDownPage.addActionListener(this); btnDownPage.setBounds(300, 390, 80, 30);return btnDownPage;private JButton getBtnDel() if (btnDel = null) btnDel = new JButton();btnDel.setBounds(new Rectangle(189, 152, 71, 30); btnDel.addActionListen
20、er(this);刪除 ");btnDel.setText(" return btnDel;private JButton getBtnModify() if (btnModify = null) btnModify = new JButton(); btnModify.setBounds(new Rectangle(342, 152, 71, 30); btnModify.addActionListener(this);btnModify.setText("更新 ");return btnModify;private JButton getBtnQue
21、ry() if (btnQuery = null) btnQuery = new JButton();btnQuery.setBounds(new Rectangle(484, 152, 71, 30); btnQuery.addActionListener(this);btnQuery.setText(" 查找 ");return btnQuery;JFrame getJFrame() if (jFrame = null) jFrame = new JFrame(); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
22、); jFrame.setBounds(new Rectangle(450, 250, 610, 454); jFrame.setContentPane(getJContentPane();jFrame.setTitle(" 學(xué)生信息管理系統(tǒng) ");return jFrame;private JPanel getJContentPane() if (jContentPane = null) lblGdp = new JLabel();lblGdp.setBounds(new Rectangle(15, 106, 63, 27); lblGdp.setText("
23、家庭住址 ");lblPopu = new JLabel(); lblPopu.setBounds(new Rectangle(285, 61, 63, 27); lblPopu.setText("成績 ");lblArea = new JLabel();lblArea.setBounds(new Rectangle(15, 61, 63, 27); lblArea.setText("學(xué)院 ");lblRegion = new JLabel();lblRegion.setBounds(new Rectangle(285, 17, 63, 27)
24、;lblRegion.setText("專業(yè) ");lblName = new JLabel(); lblName.setBounds(new Rectangle(15, 17, 63, 27); lblName.setText("姓名 ");jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(lblName, null); jContentPane.add(getTfName(), null); jContentPane.add(lblRegion, n
25、ull); jContentPane.add(getCbRegion(), null); jContentPane.add(lblArea, null); jContentPane.add(getTfArea(), null); jContentPane.add(lblPopu, null); jContentPane.add(getTfPopu(), null); jContentPane.add(lblGdp, null); jContentPane.add(getTfGDP(), null); jContentPane.add(getBtnAdd(), null); jContentPa
26、ne.add(getBtnDel(), null); jContentPane.add(getBtnModify(), null); jContentPane.add(getBtnQuery(), null); jContentPane.add(getBtnUpPage(), null); jContentPane.add(getBtnDownPage(), null); return jContentPane;public void actionPerformed(ActionEvent e) if (e.getActionCommand().equals(" selectAll(
27、); else if (e.getActionCommand().equals(" selectDownPage(); else if (e.getActionCommand().equals(" selectUpPage(); else if (e.getActionCommand().equals(" if (tfName.getText().equals("")| cbRegion.getSelectedItem().equals("| tfArea.getText().equals("") | tfPopu
28、.getText().equals("") | tfGDP.getText().equals("") JOptionPane.showMessageDialog(jFrame, " else Student co = new Student(); co.setSname(tfName.getText(); co.setSpro(String) cbRegion.getSelectedItem(); co.setSdept(tfArea.getText(); co.setSgrade(tfPopu.getText();查找 ") 下一頁
29、 ") 上一頁 ") 添加") 請(qǐng)選擇 ")請(qǐng)?zhí)顚懴嚓P(guān)信息 ");co.setSaddress(tfGDP.getText();boolean flag = SchoolOperate.add(co);if (flag) JOptionPane.showMessageDialog(jFrame, " else JOptionPane.showMessageDialog(jFrame, " else if (e.getActionCommand().equals("if(!tfName.getText().equal
30、s("")String key = tfName.getText();boolean flag = SchoolOperate.del(key);if (flag) JOptionPane.showMessageDialog(jFrame, " else JOptionPane.showMessageDialog(jFrame, "else JOptionPane.showMessageDialog(jFrame, " else if (e.getActionCommand().equals("if (!tfName.getText(
31、).equals("")&& !cbRegion.getSelectedItem().equals("&& !tfArea.getText().equals("")&& !tfPopu.getText().equals("")&& !tfGDP.getText().equals("") Student cou = new Student(); cou.setSname(tfName.getText();cou.setSpro(String)c
32、bRegion.getSelectedItem(); cou.setSdept(tfPopu.getText();cou.setSgrade(tfArea.getText();cou.setSaddress(tfGDP.getText();boolean flag = SchoolOperate.modify(cou); if(flag)JOptionPane.showMessageDialog(jFrame, "else JOptionPane.showMessageDialog(jFrame, " else JOptionPane.showMessageDialog(j
33、Frame, "public void setValues(Object obj) 添加成功添加失敗刪除") 刪除成功刪除失敗");");");");請(qǐng)?zhí)顚懸粋€(gè)國家名字 ");更新") 請(qǐng)選擇 ")更新成功 ");更新失敗 ");請(qǐng)?zhí)顚懴鄳?yīng)的信息 ");public void selectAll() String spro=cbRegion.getSelectedItem().toString(); List<Student> list = SchoolOpera
34、te.queryFirst(); Object datavalues = new Objectlist.size()5;for (int i = 0; i < list.size(); i+) Student co = list.get(i); datavaluesi0 = co.getSname(); datavaluesi1 = co.getSpro(); datavaluesi2 = co.getSdept(); datavaluesi3 = co.getSgrade(); datavaluesi4 = co.getSaddress(); tm = new TableModel()
35、; this.setValues(datavalues); table = new JTable(tm); table.updateUI();JScrollPane jsp = new JScrollPane(table); jsp.setBounds(0, 200, 600, 182); jContentPane.add(jsp); public void selectDownPage() List<Student> list = SchoolOperate.downPage(); if (list != null) Object datavalues = new Objectl
36、ist.size()5; for (int i = 0; i < list.size(); i+) Student co = list.get(i);datavaluesi0 = co.getSname(); datavaluesi1 = co.getSpro();datavaluesi2 = co.getSdept(); datavaluesi3 = co.getSgrade();datavaluesi4 = co.getSaddress(); this.setValues(datavalues); table.updateUI();已經(jīng)是最后一頁 "); else JOpt
37、ionPane.showMessageDialog(jFrame, " public void selectUpPage() List<Student> list = SchoolOperate.upPage();if (list != null) Object datavalues = new Objectlist.size()5; for (int i = 0; i < list.size(); i+) Student co = list.get(i);datavaluesi0 = co.getSname();datavaluesi1 = co.getSpro(
38、);datavaluesi2 = co.getSdept();datavaluesi3 = co.getSgrade();datavaluesi4 = co.getSaddress();this.setValues(datavalues); table.updateUI(); else 已經(jīng)是第一頁 ");JOptionPane.showMessageDialog(jFrame, "針對(duì)數(shù)據(jù)庫的增刪改查操作方法類 ;package edu;public class SchoolOperate static int i = 1;static int x = 0; public
39、 static List<Student> queryFirst() String sql = "select top 9 * from student order by sname" List<Student> list = query(sql);return list;public static List<Student> downPage() int y = queryCount(); List<Student> list = null;int count = 0; /總頁數(shù)if (y % 5 = 0) count =
40、y / 5; else count = y / 5 + 1;if (i < count) x = (+i) - 1) * 5;String sql = "select top "+ " * from (select * from student where sname not in(select top "+ x + " sname from student order by sname) as A " list = query(sql); else if (i >= count) list = null;return l
41、ist;public static boolean login(String userName,String password) boolean result=false;Connection con = DBConnection.getConnection();String sql="select passWord from login where userName="PreparedStatement ps = null;ResultSet rs = null;tryps=con.prepareStatement(sql);ps.setObject(1, userNam
42、e); rs=ps.executeQuery();while(rs.next() if(password.equals(rs.getString("passWord").trim() result=true;catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();finallytryif(rs!=null)rs.close();catch(SQLException e)e.printStackTrace();try if(ps!=null) ps.close(); catch
43、(SQLException e) e.printStackTrace(); tryif(con!=null)con.close();catch(SQLException e)e.printStackTrace(); return result;public static int queryCount() int count = 0;Connection conn = DBConnection.getConnection(); String sql = "select count(*) from student"Statement stmt = null;ResultSet
44、rs = null;try stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while (rs.next() count = rs.getInt(1); catch (SQLException e) e.printStackTrace(); finally try if (rs != null)rs.close();if (stmt != null)stmt.close();if (conn != null)conn.close(); catch (SQLException e) e.printStackTrace();r
45、eturn count;public static List<Student> query(String sql) Connection conn = DBConnection.getConnection(); List<Student> list = new ArrayList<Student>(); Statement stmt = null;ResultSet rs = null;try stmt = conn.createStatement();rs = stmt.executeQuery(sql);while (rs.next() Student
46、cou = new Student(); cou.setSname(rs.getString(1);cou.setSpro(rs.getString(2); cou.setSdept(rs.getString(3);cou.setSgrade(rs.getString(4); cou.setSaddress(rs.getString(5);list.add(cou); catch (SQLException e) e.printStackTrace(); finally try if (rs != null)rs.close();if (stmt != null) stmt.close();i
47、f (conn != null) conn.close(); catch (SQLException e) e.printStackTrace(); return list;public static List<Student> upPage() List<Student> list = null;if (i > 2) x = (-i) - 1) * 5;String sql = "select top "+ " * from (select * from student where sname not in(select top &
48、quot;+ x + " sname from student order by sname) as A " list = query(sql); else if (i = 2) list = queryFirst();i-; else if (i < 2) list = null;return list;public static boolean add(Student cou) Connection conn = DBConnection.getConnection(); PreparedStatement pstmt = null;String sql = &q
49、uot;insert into student values(,)"int x = 0;try pstmt = conn.prepareStatement(sql);pstmt.setString(1, cou.getSname();pstmt.setString(2, cou.getSpro(); pstmt.setString(3, cou.getSdept();pstmt.setString(4, cou.getSgrade();pstmt.setString(5, cou.getSaddress();x = pstmt.executeUpdate(); catch (SQLE
50、xception e) e.printStackTrace(); finally try if (pstmt != null) pstmt.close();if (conn != null) conn.close(); catch (SQLException e) e.printStackTrace();if (x = 1) return true; else return false;public static boolean del(String key) Connection conn = DBConnection.getConnection(); PreparedStatement s
51、tmt = null;String sql = "delete from student where sname =" int x = 0;try stmt = conn.prepareStatement(sql); stmt.setString(1, key);x = stmt.executeUpdate(); catch (SQLException e) e.printStackTrace(); finally try if (stmt != null) stmt.close();if (conn != null) conn.close(); catch (SQLException e) e.printStackTrace();if (x = 1) return true; else return false;public static boolean modify(Student cou) Connection conn = DBConnection.getConnection();PreparedStatement pstmt = null;String sql = "update student set spro=,sdept=,sgrade=,saddress= where sname =" int x = 0;try ps
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度LED燈具安裝與節(jié)能效果評(píng)估合同3篇
- 2024糧食購銷代理合作合同版B版
- 2024薪資保密制度與員工隱私保護(hù)專項(xiàng)合同3篇
- 2025年度現(xiàn)代農(nóng)業(yè)土地承包種植技術(shù)引進(jìn)合同3篇
- 2025年度智能大門研發(fā)與購銷合同4篇
- 2025年度數(shù)據(jù)中心能源優(yōu)化承包經(jīng)營協(xié)議4篇
- 2024水泵安裝項(xiàng)目施工合作合同版B版
- 2025年度五星級(jí)酒店廚師服務(wù)合同細(xì)則4篇
- 2024跨越國界的藝術(shù)品買賣合同
- 2025年度水利工程承攬工程施工合同4篇
- 銳途管理人員測評(píng)試題目的
- 焊接材料-DIN-8555-標(biāo)準(zhǔn)
- 工程索賠真實(shí)案例范本
- 重癥醫(yī)學(xué)科運(yùn)用PDCA循環(huán)降低ICU失禁性皮炎發(fā)生率品管圈QCC持續(xù)質(zhì)量改進(jìn)成果匯報(bào)
- 個(gè)人股權(quán)證明書
- 醫(yī)院運(yùn)送工作介紹
- 重癥患者的容量管理
- 學(xué)習(xí)游戲?qū)χ行W(xué)生學(xué)業(yè)成績的影響
- 小學(xué)四年級(jí)上冊(cè)遞等式計(jì)算100題及答案
- 新版?zhèn)€人簡歷Excel表格模板共2聯(lián)
- (完整)中國象棋教案
評(píng)論
0/150
提交評(píng)論