




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、數據庫程序設計大作業班級:2012級軟件外包服務一班學號:201215140117姓名: 。時間:2013-6-19 1功能描述1.1 功能簡介用swing做出圖形化界面形式,實現數據庫的增刪改查把員工表跟部門表連接起來,實現數據的增加,刪除,修改,查找。1.2 實現步驟(1)安裝好虛擬機,并在其下確認oracle已安裝成功(可以在dos下輸入相關命令來檢查是否安裝成功)。(2)在網絡中心修改pc機上的VMware Network Adapter的IP、子網頁碼(默認)、網關。(3)修改虛擬機的IP、網掩碼(默認)、網關,確保PC機上的網關和虛擬機的IP一致。(在控制面板>網絡和共享中心
2、>本地連接3>屬性中,修改IP、網掩碼)(4)在PC機的dos命令控制臺ping虛擬機的IP,確保正常,能ping通(即將虛擬機內外ping通)。(5)配置好虛擬機下的oracle的數據庫和監聽。(6)在eclipse中編寫相關代碼,并用jtable實現圖形化界面,用以實現與數據庫的連接和操作數據庫等功能。(7)在eclipse中導入數據庫的驅動。(8)運行eclipse,查看運行結果。2. 核心代碼2.11. 數據庫連接package .dbc;import java.sql.Connection;import java.sql.DriverManager
3、;import java.sql.ResultSet;import java.sql.SQLException;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 = "jd
4、bc:oracle:thin:28:1521/WFJ"conn = 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
5、.out.print("t");System.out.print(rs.getString("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 (ClassNotFoundExcept
6、ion e) e.printStackTrace(); 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) / TODO Auto-generated catch blocke.printStackTrace();2. 生成get set方法package edu;public class Country pri
7、vate String department_id; private String department_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;
8、 public void setdepartment_name(String department_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(Str
9、ing location_idn) this.location_id = location_id; 3實現方法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;i
10、mport javax.swing.JButton;import javax.swing.JFrame;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
11、extends JFrameprivate JTextField department_idField;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", &qu
12、ot;manager_id", "location_id"private 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);departmen
13、t_idField = new JTextField();department_idField.setBounds(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 JTe
14、xtField();department_nameField.setBounds(365, 7, 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_i
15、dField.setColumns(10);manager_idField.setBounds(100, 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);locatio
16、n_idField.setBounds(365, 33, 96, 19);getContentPane().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
17、 JButton("刪除");btnDel.addActionListener(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 action
18、Performed(ActionEvent e) update(););btnUpdate.setBounds(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(
19、).add(btnFind);model = new DefaultTableModel(columns, 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.ge
20、tValueAt(row, 2);manager_idField.setText(String) 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(EXI
21、T_ON_CLOSE);setLocationRelativeTo(null);setLocation(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_idF
22、ield.getText();stu.location_id = location_idField.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 =
23、0; i < data.size(); i+)if (tmp.equals(data.get(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 vo
24、id showTable() removeRows();for (int i = 0; i < 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
25、 public String department_id;public String department_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(
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年注會考生需建立的復習適應性與反思機制試題及答案
- 2024年項目管理核心試題及答案
- 農藝師考試問題解析技巧試題及答案
- 項目管理文件管理試題及答案
- 2024年微生物技術的市場潛力試題及答案
- 注會考試全科試題及答案解析
- 水鉆過路打孔施工方案
- 生產橋拆除重建施工方案
- 考生必看2025年證券試題及答案
- 電玩具高級多傳感器融合技術考核試卷
- 年度設備維護保養計劃表
- 幼兒園中班語言《跑跑鎮》課件
- 引水隧洞回填灌漿技術交底
- 送達地址確認書(樣本)
- 危險源辨識風險評價記錄表格范例范例
- 房建工程風險點臺賬
- 數學-二年級(下冊)-人教版-《混合運算-解決問題》教學課件
- 行政訴訟證據(39頁)ppt課件
- T∕CHAS 10-4-13-2020 中國醫院質量安全管理 第4-13部分:醫療管理住院患者健康教育
- 量化策略設計及實戰應用PPT通用課件
- 器官移植PPT課件
評論
0/150
提交評論