汽车站管理系统

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

《数据库原理》课程设计报告
设计题目:汽车站管理系统
系别:计算机与信息科学系
学生姓名:
学号:
指导教师:
专业:
班级:
完成时间:
目录
一、需求分析
(1)系统综合需求 (3)
(2)系统逻辑模型 (3)
二、系统设计
(1)概念结构设计 (4)
(2)逻辑结构设计 (4)
(3)相关SQL语句操作 (5)
三、详细设计
(1)开发平台及工具 (8)
(2) java实现相关代码 (8)
(3)系统运行相关解析 (22)
四、参考文献 (26)
五、设计总结 (27)
一、需求分析
(一)系统综合需求
主要实现的功能是汽车站驾驶人员和路线及汽车等基本信息进行管理,包括浏览驾驶员信息、路线信息,查询和统计一些驾驶员、汽车等数据,修改驾驶员行走的路线信息等。

1.以用户需求为方针,以便操作户为原则,体系将在统一的WINDOWS 操作体系图形界面下供应各类适用成果,尽年夜概低落使用前的进修、执行和使用中的维护时刻。

2.近于手工的操作,直不雅的图形用户界面,美不雅、友好、年夜略易用:悉数菜单,窗口,操作方法均为win98气概。

操作便利,丰裕思量前台操作职员操作前说起风俗,有精采的易用性。

(二)系统逻辑模型
实体E-R图
二、系统设计
(一)概念结构设计
2.汽车表car:
3.路线表line
(二)逻辑结构设计
1.驾驶员表driver
CREATE TABLE driver
(
driverID char(20) primary key,
car_ID char(20) NOT NULL ,
name char(20)unique,
brithday char(20),
sex char(2),
standing char(20),
foreign key (car_ID) references car(car_ID ) );
2.汽车表car:
创建汽车表表:
CREATE TABLE car
(
car_ID char(20)primary key,
type char(20) ,
capacity char(20) ,
);
3.路线表line
创建路线表:
CREATE TABLE line
(
line_ID char(20)primary key,
destination char(20) not null,
take_time char(20) ,
start_address char(20) not null,
ticket_price char(20) not null
);
4.汽车路线表car_line
创建汽车路线表:
CREATE TABLE car_line
(
carID char(20),
lineID char(20),
primary key(carID,lineID)
);
5.用户表user_ID.
创建用户表表:
CREATE TABLE user_ID
(
username varchar(20),
password varchar(20),
primary key(username,password)
);
(三)相关SQL语句操作
插入数据
1.汽车表数据
insert into car values('091201','飞鹤','45');
insert into car values('091202','快鹿','40');
insert into car values('091203','鸵鸟','42');
insert into car values('091204','风火轮','45');
insert into car values('091205','筋斗云','38');
insert into car values('091206','白龙马','42');
insert into car values('091207','毛驴','36');
insert into car values('091208','青牛','50');
2.驾驶员数据
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491001','091201','吴士','1981','1','6');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491002','091204','孙悟','1974','1','15');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491003','091203','李娇','1979','0','9');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491004','091202','夏雨荷','1983','0','6');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491005','091205','刘备','1977','1','16');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491006','091208','诸葛亮','1985','1','4');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491007','091206','陈娜','1975','0','17');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491008','091207','张海风','1978','1','10');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491009','091201','朱翠翠','1980','0','8');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491010','091204','赵薇','1988','0','1');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491011','091208','李鸣','1978','1','12');
insert into driver (driverID,car_ID,name,brithday,sex,standing)
values ('19491012','091203','周杰磊','1981','1','4');
3.路线表数据
insert into line (line_ID,destination,take_time,start_address,ticket_price) values ('201001','上海','3小时','南京','123');
insert into line (line_ID,destination,take_time,start_address,ticket_price) values ('201002','南通','4小时','南京','233');
insert into line (line_ID,destination,take_time,start_address,ticket_price) values ('201003','苏州','3个半小时','南京','256');
insert into line (line_ID,destination,take_time,start_address,ticket_price) values ('201004','盐城','3小时20分','南京','330');
insert into line (line_ID,destination,take_time,start_address,ticket_price) values ('201005','泰州','2个半小时','南京','450');
insert into line (line_ID,destination,take_time,start_address,ticket_price) values ('201006','扬州','2小时','南京','326');
insert into line (line_ID,destination,take_time,start_address,ticket_price) values ('201007','上海','3小时','南京','521');
insert into line (line_ID,destination,take_time,start_address,ticket_price) values ('201008','苏州','3小时','南京','430');
4.汽车路线表数据
insert into car_line (carID,lineID) values ('91202','201001');
insert into car_line(carID,lineID) values ('91207','201002');
insert into car_line(carID,lineID) values ('91208','201007');
insert into car_line(carID,lineID) values ('91206','201003');
insert into car_line (carID,lineID) values ('91205','201008');
insert into car_line (carID,lineID) values ('91204','201005');
insert into car_line (carID,lineID) values ('91201','201004');
insert into car_line (carID,lineID) values ('91203','201006');
insert into car_line (carID,lineID) values ('91202','201003');
insert into car_line (carID,lineID) values ('91206','201006');
5.用户表数据
insert into user_ID values('邱冬','123456');
建立索引
建立索引遵循的规律:
1.建立在where子句经常引用的列上,
2.经常需要排序的列上,
3.连接属性列上等
create index car_index on car(car_ID);
--汽车表在汽车编号字段上建立索引
create index driver_index on driver(driverID);
--驾驶员表在驾驶员编号字段上建立索引
create index line_index on line(lineID);
--路线表在路线编号字段上建立索引
create index take_time_index on line(take_time);
--路线表在路线所需时间上建立索引,以备查询各路线所需时间
⏹建立视图
1.创建过程take_time_list,查询各路线所花时间:
create view take_time_list
as
select line_ID,take_time
from line;
2.创建过程ticket_price,查询各路线所需票价
create view ticket_price
as
select destination,start_address,ticket_price
from line;
3.创建过程car_line_driver,查询各路线行驶的所有驾驶员及车辆
create view car_line_driver
as
select line.destination,start_address,driverID,car.car_ID
from car,line,driver
三、详细设计
(一)开发平台及工具
●开发工具: eclipse 7.0
● DBMS: Microsoft SQL Sever 2000
●连接:JDBC 连接SQL Server 2000
(二) java实现相关代码
➢连接代码
package Select;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class lianjie {
public static Connection getConnection() {
Connection con=null;
try{ //加载JDBC驱动
StringdriverName="com.microsoft.sqlserver.jdbc.SQLServerDriver
";
String dbURL= "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=db_car"; String userName = "sa"; //默认用户名
String userPwd = "123456"; //密码
Class.forName(driverName);//注册con=DriverManager.getConnection(dbURL,userName,userPwd);
}catch(Exception ex){ex.printStackTrace();}return con;
}}
➢登陆窗体
package Fram.login;
public class Login extends JDialog {
private JPasswordField passwordField;
private JTextField textField_user;
private JTextField textField;
static Login dialog;
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
dialog = new Login();
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();}}});}
public Login() {
super();
setTitle("登陆系统");
getContentPane().setLayout(null);
setBounds(100, 100, 435, 281);
final JLabel label = new JLabel();
label.setForeground(Color.RED);
label.setFont(new Font("", Font.PLAIN, 26));
label.setBackground(Color.CYAN);
label.setText(" 登录车站管理系统");
label.setBounds(66, 0, 257, 100);
getContentPane().add(label);
textField = new JTextField();
textField.setBackground(Color.BLUE);
textField.setBounds(0, 0, 437, 100);
getContentPane().add(textField);
final JLabel label_1 = new JLabel();
label_1.setText("用户名");
label_1.setBounds(98, 119, 48, 18);
getContentPane().add(label_1);
textField_user = new JTextField();
textField_user.setBounds(166, 117, 87, 22);
getContentPane().add(textField_user);
passwordField = new JPasswordField();
passwordField.setBounds(166, 145, 87, 22);
getContentPane().add(passwordField);
final JLabel label_1_1 = new JLabel();
label_1_1.setText("密码");
label_1_1.setBounds(98, 147, 48, 18);
getContentPane().add(label_1_1);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
Connection conn=lianjie.getConnection();
try {
Statement s = conn.createStatement();
String sql = "select * from user_ID";
ResultSet rs = s.executeQuery(sql);
String[]name=new String[rs.getMetaData().getColumnCount()];
while(rs.next()){name[0]=rs.getString("username").toString();
name[1]=rs.getString("password").toString();}
System.out.println(textField_user.getText().toString().equals(name[0]
));
if(!textField_user.getText().equals(name[0].toString())){
JOptionPane.showMessageDialog(null, "用户名错误");
return;}
else if(!passwordField.getText().equals(name[1])){ JOptionPane.showMessageDialog(null, "密码错误");
return; }
else{
QCFram d=new QCFram();
d.setVisible(true);
dialog.setVisible(false);}
rs.close();
s.close();
conn.close();} catch (SQLException e) {
e.printStackTrace();} }});
button.setText("登陆");
button.setBounds(166, 184, 60, 22);
getContentPane().add(button);
final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
System.exit(0);}});
button_1.setText("退出");
button_1.setBounds(240, 184, 60, 22);
getContentPane().add(button_1);
Date date = new Date();
SimpleDateFormat from = new SimpleDateFormat( "yyyy-MM-dd"); String times = from.format(date);
final JLabel label_2 = new JLabel();
label_2.setForeground(new Color(0, 0, 255));
label_2.setText("当前日期 :"+times);
label_2.setBounds(166, 224, 134, 23);
getContentPane().add(label_2);
final JLabel label_2_1 = new JLabel();
label_2_1.setForeground(new Color(0, 0, 255));
label_2_1.setText("制作人:邱冬、肖旭栩");
label_2_1.setBounds(306, 224, 121, 23);
getContentPane().add(label_2_1); }}
➢主窗体
package Fram.login;
public class QCFram extends JDialog {
private JTextField textField_1;
private JTextField textField;
QCFram dialog;
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {try {
QCFram dialog = new QCFram();
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);}});
} catch (Exception e) {e.printStackTrace();}}});} public QCFram() {
super();
setTitle("车站管理系统");
getContentPane().setLayout(null);
setBounds(100, 100, 500, 362);
final JMenuBar menuBar = new JMenuBar();
menuBar.setBackground(Color.CYAN);
setJMenuBar(menuBar);
final JMenu menu = new JMenu();
menu.setText("查询");
menuBar.add(menu);
final JMenuItem newItemMenuItem = new JMenuItem();
newItemMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { jiashiyuan y=new jiashiyuan();
y.setVisible(true);}});
newItemMenuItem.setText("驾驶员");
menu.add(newItemMenuItem);
final JMenuItem newItemMenuItem_2 = new JMenuItem();
newItemMenuItem_2.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { qiche q=new qiche();q.setVisible(true);}});
newItemMenuItem_2.setText("汽车");
menu.add(newItemMenuItem_2);
final JMenuItem newItemMenuItem_3 = new JMenuItem();
newItemMenuItem_3.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { luxian l=new luxian();
l.setVisible(true);}});
newItemMenuItem_3.setText("行车路线");
menu.add(newItemMenuItem_3);
final JMenu menu_1 = new JMenu();
menu_1.setText("添加数据");
menuBar.add(menu_1);
final JMenuItem newItemMenuItem_4 = new JMenuItem();
newItemMenuItem_4.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { Ujiashiyuan y=new Ujiashiyuan();
y.setVisible(true);}});
newItemMenuItem_4.setText("添加驾驶员");
menu_1.add(newItemMenuItem_4);
final JMenuItem newItemMenuItem_5 = new JMenuItem();
newItemMenuItem_5.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { Uqiche uqi=new Uqiche();
uqi.setVisible(true);
}
});
newItemMenuItem_5.setText("添加汽车");
menu_1.add(newItemMenuItem_5);
final JMenuItem newItemMenuItem_6 = new JMenuItem();
newItemMenuItem_6.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { Uluxian lu=new Uluxian();
lu.setVisible(true);
}
});
newItemMenuItem_6.setText("添加行车路线");
menu_1.add(newItemMenuItem_6);
final JMenu menu_2 = new JMenu();
menu_2.setText("修改数据");
menuBar.add(menu_2);
final JMenuItem newItemMenuItem_7 = new JMenuItem();
newItemMenuItem_7.setText("驾驶员");
menu_2.add(newItemMenuItem_7);
final JMenuItem newItemMenuItem_8 = new JMenuItem();
newItemMenuItem_8.setText("汽车");
menu_2.add(newItemMenuItem_8);
final JMenuItem newItemMenuItem_9 = new JMenuItem();
newItemMenuItem_9.setText("行车路线");
menu_2.add(newItemMenuItem_9);
final JMenuItem newItemMenuItem_1 = new JMenuItem();
newItemMenuItem_1.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) {
System.exit(0);}});
newItemMenuItem_1.setBackground(Color.CYAN);
newItemMenuItem_1.setText("退出");
menuBar.add(newItemMenuItem_1);
final JLabel label = new JLabel();
label.setForeground(new Color(255, 0, 0));
label.setFont(new Font("", Font.PLAIN, 16));
Connection conn=lianjie.getConnection();
Statement s;
try {
s = conn.createStatement();
String sql = "select * from user_ID";
ResultSet rs = s.executeQuery(sql); //执行sql语句 String[]name=new
String[rs.getMetaData().getColumnCount()];
while(rs.next()){
name[0]=rs.getString("username").toString();
name[1]=rs.getString("password").toString();}
rs.close();
s.close();
conn.close();
Date date = new Date();
SimpleDateFormat from = new SimpleDateFormat( "yyyy-MM-dd");
String times = from.format(date);
label.setText("操作员:"+name[0].toString()+" 当前日期:"+times);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();}
label.setBounds(177, 267, 297, 26);
getContentPane().add(label);
textField_1 = new JTextField();
textField_1.setBackground(new Color(153, 204, 255));
textField_1.setBounds(0, 0, 492, 261);
textField_1.setEditable(false);
getContentPane().add(textField_1);}
private static void addPopup(Component component, final JPopupMenu popup) {
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger())
showMenu(e);
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger())
showMenu(e);}
private void showMenu(MouseEvent e) {
popup.show(e.getComponent(), e.getX(), e.getY());}});}} ➢驾驶员信息查询窗体
package Select;
public class jiashiyuan extends JFrame {
private JTextField textField;
private JScrollPane scrollPane;
private JTable table;
private String name[]={"驾驶员编号","汽车编号","姓名","生日","性别","工作年限"};
private String[][]data;
static jiashiyuan frame;
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame= new jiashiyuan();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();}}});}
public jiashiyuan() {
super();
setResizable(false);
setTitle("驾驶员");
getContentPane().setLayout(null);
setBounds(100, 100, 587, 375);
scrollPane = new JScrollPane();
scrollPane.setBounds(0, 0, 580, 245);
Connection conn=lianjie.getConnection();
Connection conn1=lianjie.getConnection();
try {
Statement s = conn.createStatement();
String sql = "select * from driver";
ResultSet rs = s.executeQuery(sql); //执
行sql语句
Statement s1 = conn1.createStatement();
String sql1 = "select * from driver";
ResultSet rs1= s1.executeQuery(sql1); //
执行sql语句
int row=0;//总行数
while(rs1.next())
{ row++;}
data = new
String[row][rs.getMetaData().getColumnCount()];
int ii=0;
while(rs.next())
{
data[ii][0]=rs.getString("driverID");
data[ii][1]=rs.getString("car_ID");
data[ii][2]=rs.getString("name");
data[ii][3]=rs.getString("brithday");
data[ii][4]=rs.getString("sex");
data[ii][5]=rs.getString("standing");
ii++; } rs.close();
s.close();
s1.close();
rs1.close();
conn.close();
table=new JTable(data,name);
table.getTableHeader().setPreferredSize(new Dimension(table.getTableHeader().getWidth(),30));
} catch (SQLException e) {e.printStackTrace();} scrollPane.setViewportView(table);
getContentPane().add(scrollPane);
final JLabel label = new JLabel();
label.setForeground(new Color(255, 0, 0));
label.setFont(new Font("", Font.PLAIN, 15));
label.setText("驾驶员信息");
label.setBounds(279, 280, 76, 28);
getContentPane().add(label);
Date date = new Date();
SimpleDateFormat from = new SimpleDateFormat( "yyyy-MM-dd");
String times = from.format(date);
final JLabel label_1 = new JLabel();
label_1.setForeground(new Color(255, 0, 0));
label_1.setText(times);
label_1.setBounds(279, 314, 66, 18);
getContentPane().add(label_1);} }
➢添加驾驶员信息窗体
package Updata;
public class Ujiashiyuan extends JDialog {
private JTextField textField_6;
private JTextField textField_5;
private JTextField textField_4;
private JTextField textField_3;
private JTextField textField_2;
private JTextField textField;
static Ujiashiyuan dialog1;
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
dialog1 = new Ujiashiyuan();
dialog1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);}});
dialog1.setVisible(true);
} catch (Exception e) {
e.printStackTrace();}}});}
public Ujiashiyuan() {
super();
getContentPane().setLayout(null);
setTitle("添加驾驶员");
setResizable(false);
setBounds(100, 100, 287, 374);
final JLabel label = DefaultComponentFactory.getInstance().createLabel("驾驶员编号");
label.setForeground(new Color(255, 0, 255));
label.setFont(new Font("", Font.PLAIN, 16));
label.setBounds(24, 36, 81, 26);
getContentPane().add(label);
final JLabel label_1 = DefaultComponentFactory.getInstance().createLabel("汽车编号");
label_1.setForeground(new Color(255, 0, 255));
label_1.setFont(new Font("", Font.PLAIN, 16));
label_1.setBounds(24, 76, 81, 26);
getContentPane().add(label_1);
final JLabel label_2 = DefaultComponentFactory.getInstance().createLabel("姓名");
label_2.setForeground(new Color(255, 0, 255));
label_2.setFont(new Font("", Font.PLAIN, 16));
label_2.setBounds(24, 108, 81, 26);
getContentPane().add(label_2);
final JLabel label_2_1 = DefaultComponentFactory.getInstance().createLabel("出生年月");
label_2_1.setForeground(new Color(255, 0, 255));
label_2_1.setFont(new Font("", Font.PLAIN, 16));
label_2_1.setBounds(24, 140, 81, 26);
getContentPane().add(label_2_1);
final JLabel label_2_2 = DefaultComponentFactory.getInstance().createLabel("性别");
label_2_2.setForeground(new Color(255, 0, 255));
label_2_2.setFont(new Font("", Font.PLAIN, 16));
label_2_2.setBounds(24, 186, 81, 26);
getContentPane().add(label_2_2);
final JLabel label_2_2_1 = DefaultComponentFactory.getInstance().createLabel("工作年限");
label_2_2_1.setForeground(new Color(255, 0, 255));
label_2_2_1.setFont(new Font("", Font.PLAIN, 16));
label_2_2_1.setBounds(24, 218, 81, 26);
getContentPane().add(label_2_2_1);
textField = new JTextField();
textField.setBounds(120, 40, 105, 22);
getContentPane().add(textField);
textField_2 = new JTextField();
textField_2.setBounds(120, 80, 105, 22);
getContentPane().add(textField_2);
textField_3 = new JTextField();
textField_3.setBounds(120, 112, 105, 22);
getContentPane().add(textField_3);
textField_4 = new JTextField();
textField_4.setBounds(120, 144, 105, 22);
getContentPane().add(textField_4);
textField_5 = new JTextField();
textField_5.setBounds(120, 190, 105, 22);
getContentPane().add(textField_5);
textField_6 = new JTextField();
textField_6.setBounds(120, 222, 105, 22);
getContentPane().add(textField_6);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
Connection conn=lianjie.getConnection();
try {
String sql="insert into driver values(?,?,?,?,?,?)";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setNString(1, textField.getText());
ps.setNString(2, textField_2.getText());
ps.setNString(3, textField_3.getText());
ps.setNString(4, textField_4.getText());
ps.setNString(5, textField_5.getText());
ps.setNString(6, textField_6.getText());
ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "插入失败")}}});
button.setForeground(new Color(255, 0, 255));
button.setFont(new Font("", Font.PLAIN, 16));
button.setText("添加");
button.setBounds(143, 281, 89, 28);
getContentPane().add(button);}}
➢添加行车路线窗体
package Updata;
public class Uluxian extends JDialog {
private JTextField textField_5;
private JTextField textField_4;
private JTextField textField_3;
private JTextField textField_2;
private JTextField textField;
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Uluxian dialog = new Uluxian();
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);}});
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();}}}); }
public Uluxian() {
super();
setResizable(false);
getContentPane().setLayout(null);
setBounds(100, 100, 306, 383);
final JLabel label = DefaultComponentFactory.getInstance().createLabel("路线编号");
label.setForeground(new Color(255, 0, 255));
label.setFont(new Font("", Font.PLAIN, 16));
label.setBounds(23, 28, 83, 32);
getContentPane().add(label);
final JLabel label_1 = DefaultComponentFactory.getInstance().createLabel("目的地");
label_1.setForeground(new Color(255, 0, 255));
label_1.setFont(new Font("Dialog", Font.PLAIN, 16));
label_1.setBounds(23, 66, 83, 32);
getContentPane().add(label_1);
final JLabel label_2 = DefaultComponentFactory.getInstance().createLabel("所需时间");
label_2.setForeground(new Color(255, 0, 255));
label_2.setFont(new Font("Dialog", Font.PLAIN, 16));
label_2.setBounds(23, 104, 83, 32);
getContentPane().add(label_2);
final JLabel label_3 = DefaultComponentFactory.getInstance().createLabel("出发地");
label_3.setForeground(new Color(255, 0, 255));
label_3.setFont(new Font("Dialog", Font.PLAIN, 16));
label_3.setBounds(23, 142, 83, 32);
getContentPane().add(label_3);
final JLabel label_4 = DefaultComponentFactory.getInstance().createLabel("票价");
label_4.setForeground(new Color(255, 0, 255));
label_4.setFont(new Font("Dialog", Font.PLAIN, 16));
label_4.setBounds(23, 180, 83, 32);
getContentPane().add(label_4);
textField = new JTextField();
textField.setBounds(126, 28, 109, 29);
getContentPane().add(textField);
textField_2 = new JTextField();
textField_2.setBounds(126, 70, 109, 29);
getContentPane().add(textField_2);
textField_3 = new JTextField();
textField_3.setBounds(126, 108, 109, 29);
getContentPane().add(textField_3);
textField_4 = new JTextField();
textField_4.setBounds(126, 146, 109, 29);
getContentPane().add(textField_4);
textField_5 = new JTextField();
textField_5.setBounds(126, 184, 109, 29);
getContentPane().add(textField_5);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) { Connection conn=lianjie.getConnection();
try {
String sql="insert into line values(?,?,?,?,?)"; PreparedStatement ps=conn.prepareStatement(sql);
ps.setNString(1, textField.getText());
ps.setNString(2, textField_2.getText());
ps.setNString(3, textField_3.getText());
ps.setNString(4, textField_4.getText());
ps.setNString(5, textField_5.getText());
ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, "插入失败");}}});
button.setForeground(new Color(255, 0, 255));
button.setFont(new Font("", Font.PLAIN, 16));
button.setText("添加");
button.setBounds(158, 259, 93, 39);
getContentPane().add(button); }}
➢添加汽车窗体
package Updata;
public class Uqiche extends JDialog {
private JTextField textField_3;
private JTextField textField_2;
private JTextField textField;
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Uqiche dialog = new Uqiche();
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);}});
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();}}});}
public Uqiche() {
super();
getContentPane().setLayout(null);
setTitle("添加汽车");
setResizable(false);
setBounds(100, 100, 292, 375);
final JLabel label = DefaultComponentFactory.getInstance().createLabel("汽车编号");
label.setForeground(new Color(255, 0, 255));
label.setFont(new Font("", Font.PLAIN, 16));
label.setBounds(22, 30, 98, 35);
getContentPane().add(label);
final JLabel label_1 = DefaultComponentFactory.getInstance().createLabel("类型");
label_1.setForeground(new Color(255, 0, 255));
label_1.setFont(new Font("Dialog", Font.PLAIN, 16));
label_1.setBounds(22, 88, 98, 35);
getContentPane().add(label_1);
final JLabel label_2 = DefaultComponentFactory.getInstance().createLabel("载客量");
label_2.setForeground(new Color(255, 0, 255));
label_2.setFont(new Font("Dialog", Font.PLAIN, 16));
label_2.setBounds(22, 152, 98, 35);
getContentPane().add(label_2);
textField = new JTextField();。

相关文档
最新文档