




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、數(shù)據(jù)庫程序設(shè)計大作業(yè)1功能描述1.1 功能簡介用swing做出圖形化界面形式,實(shí)現(xiàn)數(shù)據(jù)庫的增刪改查把員工表跟部門表連接起來,實(shí)現(xiàn)數(shù)據(jù)的增加,刪除,修改,查找。1.2 實(shí)現(xiàn)步驟(1)安裝好虛擬機(jī),并在其下確認(rèn)oracle已安裝成功(可以在dos下輸入相關(guān)命令來檢查是否安裝成功)。(2)在網(wǎng)絡(luò)中心修改pc機(jī)上的VMware Network Adapter的IP、子網(wǎng)頁碼(默認(rèn))、網(wǎng)關(guān)。(3)修改虛擬機(jī)的IP、網(wǎng)掩碼(默認(rèn))、網(wǎng)關(guān),確保PC機(jī)上的網(wǎng)關(guān)和虛擬機(jī)的IP一致。(在控制面板>網(wǎng)絡(luò)和共享中心>本地連接3>屬性中,修改IP、網(wǎng)掩碼)(4)在PC機(jī)的dos命令控制臺ping虛擬機(jī)
2、的IP,確保正常,能ping通(即將虛擬機(jī)內(nèi)外ping通)。(5)配置好虛擬機(jī)下的oracle的數(shù)據(jù)庫和監(jiān)聽。(6)在eclipse中編寫相關(guān)代碼,并用jtable實(shí)現(xiàn)圖形化界面,用以實(shí)現(xiàn)與數(shù)據(jù)庫的連接和操作數(shù)據(jù)庫等功能。(7)在eclipse中導(dǎo)入數(shù)據(jù)庫的驅(qū)動。(8)運(yùn)行eclipse,查看運(yùn)行結(jié)果。2. 核心代碼2.11. 數(shù)據(jù)庫連接package .dbc;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLExc
3、eption;import java.sql.Statement;public class DatabaseConnection public static void main(String args) Connection conn = null;Statement stmt = null;ResultSet rs = null;try Class.forName("oracle.jdbc.driver.OracleDriver");String url = "jdbc:oracle:thin:28:1521/WFJ"conn =
4、 DriverManager.getConnection(url, "hr", "hr");stmt = conn.createStatement();String sql = "select * from departments"rs = stmt.executeQuery(sql);while (rs.next() System.out.print(rs.getInt("department_id");System.out.print("t");System.out.print(rs.get
5、String("department_name");System.out.print("t");System.out.print(rs.getInt("manager_id");System.out.print("t");System.out.print(rs.getInt("location_id");System.out.println(); catch (ClassNotFoundException e) e.printStackTrace(); catch (SQLException e
6、) e.printStackTrace(); finally try if (rs != null) rs.close();if (stmt != null) stmt.close();if (conn != null) conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();2. 生成get set方法package edu;public class Country private String department_id; private String departm
7、ent_name; private String area; private String population; public String getdepartment_id() return department_id; public void setdepartment_id(String department_name) = department_id; public String getdepartment_name() return department_name; public void setdepartment_name(String department
8、_name) this.department_name = department_name; public String getmanager_id() return manager_id; public void setmanager_id(String manager_id) this.manager_id= manager_id; public String getlocation_id() return location_id; public void setlocation_id(String location_idn) this.location_id = location_id;
9、 3實(shí)現(xiàn)方法package tuxinghua;import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.Serializable;import java.sql.DriverManager;import java.sql.ResultSet;import java.util.ArrayList;import java.util.List;import javax.swing.JButton;import javax.swing.JFra
10、me;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.table.DefaultTableModel;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;public class AppStudent extends JFrameprivate JTextField department_idFie
11、ld;private JTextField department_nameField;private JTextField manager_idField;private JTextField location_idField;private JTable table;private DefaultTableModel model;private String columns = "department_id", "department_name", "manager_id", "location_id"priva
12、te List data;private Student tmp; public AppStudent() data = new ArrayList();getContentPane().setLayout(null);JLabel lblemployee = new JLabel("department_id");lblemployee.setBounds(12, 10, 220, 13);getContentPane().add(lblemployee);department_idField = new JTextField();department_idField.s
13、etBounds(100, 7, 96, 19); getContentPane().add(department_idField);department_idField.setColumns(10);JLabel lblAge = new JLabel("department_name");lblAge.setBounds(252, 10, 220, 13);getContentPane().add(lblAge);department_nameField = new JTextField();department_nameField.setBounds(365, 7,
14、96, 19);getContentPane().add(department_nameField);department_nameField.setColumns(10);JLabel lblStuno = new JLabel("manager_id");lblStuno.setBounds(12, 36, 220, 13);getContentPane().add(lblStuno);manager_idField = new JTextField();manager_idField.setColumns(10);manager_idField.setBounds(1
15、00, 33, 96, 19);getContentPane().add(manager_idField);JLabel lblClass = new JLabel("location_id");lblClass.setBounds(252, 36, 220, 13);getContentPane().add(lblClass);location_idField = new JTextField();location_idField.setColumns(10);location_idField.setBounds(365, 33, 96, 19);getContentPa
16、ne().add(location_idField);JButton btnAdd = new JButton("增加");btnAdd.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) add(););btnAdd.setBounds(75, 59, 77, 21);getContentPane().add(btnAdd);JButton btnDel = new JButton("刪除");btnDel.addActionListener
17、(new ActionListener() public void actionPerformed(ActionEvent e) del(););btnDel.setBounds(180, 59, 77, 21);getContentPane().add(btnDel);JButton btnUpdate = new JButton("更新");btnUpdate.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) update(););btnUpdate.set
18、Bounds(280, 59, 77, 21);getContentPane().add(btnUpdate);JButton btnFind = new JButton("查找");btnFind.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) find(););btnFind.setBounds(380, 59, 77, 21);getContentPane().add(btnFind);model = new DefaultTableModel(colu
19、mns, 0);table = new JTable(model);table.addMouseListener(new MouseAdapter()public void mouseClicked(MouseEvent e)int row = table.getSelectedRow();department_idField.setText(String) table.getValueAt(row, 0);department_nameField.setText(String) table.getValueAt(row, 2);manager_idField.setText(String)
20、table.getValueAt(row, 3);location_idField.setText(String) table.getValueAt(row, 4);tmp = getInput(););JScrollPane scrollPane = new JScrollPane(table);scrollPane.setBounds(12, 100, 571, 248);getContentPane().add(scrollPane);setDefaultCloseOperation(EXIT_ON_CLOSE);setLocationRelativeTo(null);setLocati
21、on(350,200);setSize(601, 380);setResizable(false);setVisible(true);private Student getInput() Student stu = new Student();stu.department_id= department_idField.getText();stu.department_name = department_nameField.getText();stu.manager_id = manager_idField.getText();stu.location_id = location_idField
22、.getText();return stu;private void add() data.add(getInput();showTable();private void del() for (int i = 0; i < data.size(); i+)if (tmp.equals(data.get(i) data.remove(i);break;showTable();private void update() Student stu = getInput();for (int i = 0; i < data.size(); i+)if (tmp.equals(data.get
23、(i) data.remove(i);data.add(i, stu);break;showTable();private void find() removeRows();Student stu = getInput();for (int i = 0; i < data.size(); i+) Student tmp = (Student) data.get(i);if (tmp.equals(stu) model.addRow(tmp.toArray();break;private void showTable() removeRows();for (int i = 0; i <
24、; data.size(); i+)Student stu = (Student) data.get(i);model.addRow(stu.toArray();private void removeRows() while (model.getRowCount() > 0) model.removeRow(0);public static void main(String args) new AppStudent();class Studentimplements Serializable public String department_id;public String depart
25、ment_name;public String manager_id;public String location_id;public boolean equals(Object obj) return equals(Student) obj);public boolean equals(Student obj) boolean isdepartment_id = true;if (obj.department_id != null && !"".equals(obj.department_id) isdepartment_id = department_id.equals(obj.department_id);boolean isdepartment_name = true;if (obj.department_name != null && !"".equals(obj.department_name) isdepartment_name = department_name.equals(obj.d
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 佛山施工合同范例
- 公路混凝土采購合同范例
- 事業(yè)人員招聘合同范例
- 中俄國際合同范例
- 出口股合同范例
- 偶像俱樂部協(xié)議合同范例
- 公司度分紅合同范例
- 農(nóng)村出讓土地合同范例
- 關(guān)于賣藕合同范例
- 代加工洗煤合同范例
- 體育用品開店策劃書3
- 郵政社招筆試試題及答案
- 車間精益生產(chǎn)培訓(xùn)
- 運(yùn)輸公司獎懲管理制度
- 前程無憂測試題庫28個題答案
- 無傘空投技術(shù)研究進(jìn)展及國外準(zhǔn)備階段分析
- 上海家政服務(wù)合同樣本
- 2025年春江蘇開放大學(xué)生活中的經(jīng)濟(jì)學(xué)060057綜合作業(yè)一、二參考答案
- 黑龍江省哈爾濱市第四十七中學(xué)2024-2025學(xué)年八年級下學(xué)期3月月考地理試題(含答案)
- 醫(yī)院醫(yī)療服務(wù)收費(fèi)自查自糾制度
- 了不起的狐貍爸爸課件
評論
0/150
提交評論