资源预览内容
第1页 / 共15页
第2页 / 共15页
第3页 / 共15页
第4页 / 共15页
第5页 / 共15页
第6页 / 共15页
第7页 / 共15页
第8页 / 共15页
第9页 / 共15页
第10页 / 共15页
亲,该文档总共15页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
数据库程序设计大作业班级:2012级软件外包服务一班学号:201215140117姓名: 。时间:2013-6-19 1功能描述1.1 功能简介用swing做出图形化界面形式,实现数据库的增删改查把员工表跟部门表连接起来,实现数据的增加,删除,修改,查找。1.2 实现步骤(1)安装好虚拟机,并在其下确认oracle已安装成功(可以在dos下输入相关命令来检查是否安装成功)。(2)在网络中心修改pc机上的VMware Network Adapter的IP、子网页码(默认)、网关。(3)修改虚拟机的IP、网掩码(默认)、网关,确保PC机上的网关和虚拟机的IP一致。(在控制面板网络和共享中心本地连接3属性中,修改IP、网掩码)(4)在PC机的dos命令控制台ping虚拟机的IP,确保正常,能ping通(即将虚拟机内外ping通)。(5)配置好虚拟机下的oracle的数据库和监听。(6)在eclipse中编写相关代码,并用jtable实现图形化界面,用以实现与数据库的连接和操作数据库等功能。(7)在eclipse中导入数据库的驱动。(8)运行eclipse,查看运行结果。2. 核心代码2.11. 数据库连接package org.lxh.info.dbc;import java.sql.Connection;import java.sql.DriverManager;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 = jdbc:oracle:thin:192.168.0.128: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.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 (ClassNotFoundException 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 private 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) this.name = department_id; public String getdepartment_name() return department_name; 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(String 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;import 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 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, 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);department_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 JTextField();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_idField.setColumns(10);manager_idField.setBounds(100, 33, 96, 19);getContentPane().add(manager_idField);JLabel lblClass = new JLabel(location_id);
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号