数库课程实训报告
( 2015 2016年度第2学期)
题目: 企业电理系统
专业
软件工程
学生姓名
班级
软件
学号
指导教师
完成日期
2016
目 录
目 录 2
1 课题容求 1
11课题描述 1
12 课题求 1
2 需求分析 1
21 功规定 1
22 数需求分析 2
3 系统设计 3
31 功模块设计 3
32 数库概念设计 4
322 ER图 4
33 数库逻辑设计 5
34 数库物理设计 5
35 数库表间联系 6
4系统实现 6
41登陆模块实现 6
42查询模块实现 7
43 添加模块实现 8
44 删模块实现 9
45 修改模块实现 10
46 生成电费单模块实现 10
5 代码调试功测试 11
51 测试方案 11
52 测试结果 12
6 收获体会 16
参考文献 17
附 录 18
附录1源程序部分清单 18
企业电理系统设计
1 课题容求
11课题描述
系统设计信息:
(1) 电企业(电企业编号电企业名址电话联系)
(2) 电费信息(谷价峰价)
(3) 电情况(电企业编号谷电量峰电量年月年合计电量年合计电费)
12 课题求
求够进行操作:
(1) 够统计电企业月耗电量电费
(2) 够统计查询电企业总谷电量峰电量
(3) 够统计该区峰谷电量例电费情况
(4) 维护基数
(5) 户分级理机界面良
2 需求分析
21 功规定
1理解需求
理解需求问题终解决方案间架设桥梁第步开发者户充分理解需求开始设计系统否需求定义改进设计必须量返工
面系统终端户客户调研需求规格说明书
(1)者相关电力部门学系统开始时便进入欢迎界面
(2)进入系统友界面清晰分企业信息理企业电信息理两选择
(3)点击企业信息理拉菜单中选项实现企业信息查询添加修改删操作
(4)点击企业电理信息拉菜单中选项实现企业电理信息查询添加修改删操作
(5)系统客户端运行Windows台服务器运行WindowsUnix台系统应该较图形户界面
(6)系统应该扩展性
2需求分析
需求分析客户需求中提取出软件系统够帮助户解决业务问题通户业务问题分析确定系统功需求步骤理解需求升华直接关系该系统质量分析根目开发者提出需求间建立种理解沟通机制系统需求分析应该开发员户客户起完成
22 性规定
1精度
精度需求根需项数输入输出传输程中满足种精度需求:根关键字精度查找分精确查找泛型查找精确查找精确匹配系统者知道企业名称编号快速便捷查询知道信息
2时间特性求
软件方面响应时间更新处理时间较快迅速完全满足户求
3灵活性
户需求操作方式运行环境结果精度数结构软件接口等发生变化时设计软件做适调整灵活性非常
22 数需求分析
数字典
(1)factory
名称:factory
名:
描述:企业基信息
组成:factory(num+facname+repname+tel+usefnum+usegnum+usemoney)
(2) worker
名称:worker
名:
描述:员工理员基信息
组成:worker(id+workername+password+level)
3 系统设计
31 功模块设计
32 数库概念设计
321实体属性图
322 ER图
33 数库逻辑设计
企业(编号企业名法代表)
电价(峰电量谷电量峰电价谷电价总电费)
系统户(编号姓名密码权限)
34 数库物理设计
表:
factory
列名
数类型
允许Null值
num
varchar(50)
facname
varchar(50)
repname
varchar(50)
tel
varchar(50)
usefnum
int
usegnum
int
usemoney
int
num
facname
repname
tel
usefnum
usegnum
usemoney
001
新华书店
陈国勇
17802590001
1314
1022
2333
002
苏果超市
陈博文
17802590002
1516
2253
2863
003
微软公司
毕世勇
17802590003
3685
2467
4952
004
乐天玛特
丁杰
17802590004
3011
2794
3105
005
三厂中学
陈家勇
17802590005
2422
1974
2875
表二:
worker
列名
数类型
允许Null值
id
int
否
workername
varchar(50)
否
password
varchar(50)
否
[level]
int
否
id
workername
password
[level]
111
张三
123456
1
112
李四
123456
1
113
熊
123456
2
114
熊二
123456
2
35 数库表间联系
数库中建两张表factoryworker间没直接联系代表企业信息代表员工信息
4系统实现
41登陆模块实现
private class ButtonactionPerformed implements ActionListener
登陆钮ButtonactionPerformed添加事件监视器
{
public void actionPerformed(ActionEvent e)worker表中获元组信息进行登陆面获元组登陆代码
{
ausername2getText()
spassword2getText()
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
rs(ResultSet)stmtexecuteQuery(select * from worker )
if(cequals(a)&&bequals(s))
{
messagesetText(姓名密码空)
}
else if(true)
{
while(rsnext())
{
if(rsgetString(2)equals(a)&& rsgetString(3)equals(s)&&rsgetInt(4)level)
{
messagesetText(数库连接成功)
if(level1)
{
operate2 app2new operate2()
app2setLocationRelativeTo(null)
}
else
{
operate app3new operate()
app3setLocationRelativeTo(null)
}
}
else
{
messagesetText(户名密码者身份正确)
}
}
}
rsclose()
stmtclose()
connclose()
}
42查询模块实现
private class ButtonactionPerformed implements ActionListener
查询钮ButtonactionPerformed添加事件监视器
{
public void actionPerformed(ActionEvent e)
worker表中获取元组显示系统
{
facnamesearchgetText()
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
rs(ResultSet)stmtexecuteQuery(select * from factory )
while(rsnext())
{
if(rsgetString(2)equals(facname))
{
text1setText(rsgetString(1))
text2setText(rsgetString(2))
text3setText(rsgetString(3))
text4setText(rsgetString(4))
text5setText(+(rsgetInt(5)))
text6setText(+rsgetInt(6))
text7setText(+rsgetInt(7))
}
}
rsclose()
stmtclose()
connclose()
}
43 添加模块实现
private class ButtonactionPerformed implements ActionListener
添加钮ButtonactionPerformed添加事件监视器
{
public void actionPerformed(ActionEvent e)
系统输入添加元组信息通添加钮添加数库中factory表
{
x1text1getText()
x2text2getText()
x3text3getText()
x4text4getText()
x5text5getText()
x6text6getText()
x7text7getText()
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
prepstmt1(PreparedStatement) connprepareStatement(INSERT INTO factory(numfacnamerepnametelusefnumusegnumusemoney)
+VALUES())
prepstmt1setString(1 x1)
prepstmt1setString(2 x2)
prepstmt1setString(3 x3)
prepstmt1setString(4 x4)
prepstmt1setString(5 x5)
prepstmt1setString(6 x6)
prepstmt1setString(7 x7)
prepstmt1executeUpdate()
connclose()
}
44 删模块实现
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
x1text1getText()
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
stmtexecuteUpdate(delete from factory where num+x1)
connclose()
}
45 修改模块实现
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
x1text1getText()
x2text2getText()
x3text3getText()
x4text4getText()try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
prepstmt2(PreparedStatement) connprepareStatement(update factory set numusegnumusefnumusemoney where num)
prepstmt2setString(1 x1)
prepstmt2setString(2 x2)
prepstmt2setString(3 x3)
prepstmt2setString(4 x4)
prepstmt2setString(5 x1)
prepstmt2executeUpdate()
prepstmt2close()
connclose()
}
46 生成电费单模块实现
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
facnamesearchgetText()
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
rs(ResultSet)stmtexecuteQuery(select * from factory )
while(rsnext())
{
if(rsgetString(2)equals(facname))
{
x1rsgetString(5)
x2rsgetString(6)
x3rsgetString(7)
text1setText(rsgetString(5))
text2setText(rsgetString(6))
text3setText(rsgetString(7))
}
}
rsclose()
stmtclose()
connclose()
}
5 代码调试功测试
51 测试方案
(1)分输入户理员查登陆进界面
(2)分户理员查询企业电信息
(3)添加企业电信息
(4)修改企业电信息
(5)删企业电信息
(6)生成电费单
52 测试结果
理员登陆
理员登陆界面
理员登陆查询界面
户登陆查询界面
点击添加界面
输入数
添加成功
点击修改进行修改信息
修改成功
点击删出现界面
删成功
点击生成电费单出现界面
桌面生成电费单
6 收获体会
次课程设计心体会通实践收获:
开始接触数结构课程设计真挺难会逻辑方面问题具备动手力脑子里总团火题目开始想法想逻辑实现编写程序需编写开始难说知道里入手参考书里程序仿结构步步做现单链表种操作已算较熟练知道光理知识远远够需动手写然手擒
二根实中遇问题学程中注意点:
1认真专业实验课实践中锻炼
2写程序程中考虑周严密
3做设计时候信心耐心切勿浮躁
4认真学课知识掌握课中知识点基础学会灵活运
5课余时间里写程序熟练掌握调试程序程中遇常见错误便节省调试程序时间
参考文献
[1] 钱雪忠王燕玲林挺数库原理技术[M]北京:清华学出版社2011
[2] 钱雪忠罗海驰陈国俊数库原理技术课程设计[M]北京:清华学出版社2014
附 录
附录1源程序部分清单
附录11record代码
import javaawt*
import javaawtevent*
import javasqlConnection
import javasqlDriverManager
import javasqlSQLException
import javasqlResultSet
import javasqlStatement
import javaxswing*
public class Record extends JFrame
{
private static final long serialVersionUID 1L
private JLabel usernamepassword
private JTextField username2
private JTextField password2message
private JButton button
private JRadioButton box1box2
private ButtonGroup buttongroup
private String as
private String c
private String b
private int level2
private String juzi
public Record()
{
super(Record)
setSize(300300)
try
{
UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName())
}catch(Exception e){}
Container containergetContentPane()
containersetBackground(ColorlightGray)
containersetLayout(null)
usernamenew JLabel(户名JLabelRIGHT)
passwordnew JLabel( 密码 JLabelRIGHT)
buttongroupnew ButtonGroup()
box1new JRadioButton(员工true)
box2new JRadioButton(理员)
username2new JTextField(20)
password2new JTextField(20)
messagenew JTextField(欢迎企业电理系统)
messagesetHorizontalAlignment(JTextFieldCENTER)
buttonnew JButton(登录)
usernamesetBounds(50 50 50 25)
username2setBounds(100 50 120 25)
passwordsetBounds(50 85 50 25)
password2setBounds(10085 120 25)
messagesetBounds(55160 190 25)
box1setBounds(501205025)
box2setBounds(1101207025)
buttonsetBounds(190 120 60 25)
buttongroupadd(box1)
buttongroupadd(box2)
ButtonactionPerformed buttonernew ButtonactionPerformed()
buttonaddActionListener(buttoner)
RadioButtonHandler handler new RadioButtonHandler()
box1addItemListener(handler)
box2addItemListener(handler)
containeradd(username)
containeradd(username2)
containeradd(password)
containeradd(password2)
containeradd(box1)
containeradd(box2)
containeradd(button)
containeradd(message)
setVisible(true)
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE)
}
public static void main(String[] args)
{
Record appnew Record()
appsetLocationRelativeTo(null)
}
private class RadioButtonHandler implements ItemListener
{
public void itemStateChanged(ItemEvent event)
{
if(box1isSelected())
{
messagesetText(员工登录)
level2
}
else if(box2isSelected())
{
messagesetText(理员登录)
level1
}
}
}
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)登录
{
ausername2getText()
spassword2getText()
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is)}
Statement stmt
ResultSet rs
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
String drivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
rs(ResultSet)stmtexecuteQuery(select * from worker )
if(cequals(a)&&bequals(s))
{
messagesetText(姓名密码空)
}
else if(true)
{
while(rsnext())
{
if(rsgetString(2)equals(a)&& rsgetString(3)equals(s)&&rsgetInt(4)level)
{
messagesetText(数库连接成功)
if(level1)
{
operate2 app2new operate2()
app2setLocationRelativeTo(null)
}
else
{
operate app3new operate()
app3setLocationRelativeTo(null)
}
}
else
{
messagesetText(户名密码者身份正确)
}
}
}
rsclose()
stmtclose()
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
}
附录12 operate代码
import javaawtColor
import javaawtContainer
import javaawteventActionEvent
import javaawteventActionListener
import javasqlConnection
import javasqlDriverManager
import javasqlSQLException
import javaxswingJButton
import javaxswingJFrame
import javaxswingJLabel
import javaxswingJTextField
import javaxswingUIManager
import javasqlResultSet
import javasqlStatement
public class operate extends JFrame
{
private static final long serialVersionUID 1L
private JButton b1b2b3b4b5b6
private JLabel c1c2c3c4c5c6c7
private JTextField text1text2text3text4text5text6text7
private JTextField search
private JLabel name
private String facname
public operate()
{
super(operate)
setSize(700400)
try
{
UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName())
}catch(Exception e){}
Container containergetContentPane()
namenew JLabel(输入企业名JLabelRIGHT)
c1new JLabel(企业编号JLabelRIGHT)
c2new JLabel(企业名称JLabelRIGHT)
c3new JLabel(企业代表JLabelRIGHT)
c4new JLabel(企业联系电话JLabelRIGHT)
c5new JLabel(企业谷电量JLabelRIGHT)
c6new JLabel(企业峰电量JLabelRIGHT)
c7new JLabel(企业电费JLabelRIGHT)
b1new JButton(查询)
b2new JButton(取消)
b3new JButton(添加)
b4new JButton(删)
b5new JButton(修改)
b6new JButton(生成电费单)
text1new JTextField(200)
text2new JTextField(200)
text3new JTextField(200)
text4new JTextField(200)
text5new JTextField(200)
text6new JTextField(200)
text7new JTextField(200)
searchnew JTextField(60)
namesetBounds(80 50 100 30)
c1setBounds(80 100 100 30)
c2setBounds(80 130 100 30)
c3setBounds(80 160 100 30)
c4setBounds(80 190 100 30)
c5setBounds(80 220 100 30)
c6setBounds(80 250 100 30)
c7setBounds(80 280 100 30)
searchsetBounds(200 50 100 25)
b1setBounds(370 526025)
b2setBounds(500526025)
b3setBounds(150 3306025)
b4setBounds(250 3306025)
b5setBounds(350 3306025)
b6setBounds(450 33010025)
text1setBounds(20010035030)
text2setBounds(20013035030)
text3setBounds(20016035030)
text4setBounds(20019035030)
text5setBounds(20022035030)
text6setBounds(20025035030)
text7setBounds(20028035030)
ButtonactionPerformed buttonernew ButtonactionPerformed()
ButtonactionPerformed2 buttoner2new ButtonactionPerformed2()
ButtonactionPerformed3 buttoner3new ButtonactionPerformed3()
ButtonactionPerformed4 buttoner4new ButtonactionPerformed4()
ButtonactionPerformed5 buttoner5new ButtonactionPerformed5()
ButtonactionPerformed6 buttoner6new ButtonactionPerformed6()
b1addActionListener(buttoner)
b2addActionListener(buttoner2)
b3addActionListener(buttoner3)
b4addActionListener(buttoner4)
b5addActionListener(buttoner5)
b6addActionListener(buttoner6)
containeradd(b1)
containeradd(b2)
containeradd(b3)
containeradd(b4)
containeradd(b5)
containeradd(b6)
containeradd(search)
containeradd(text1)
containeradd(text2)
containeradd(text3)
containeradd(text4)
containeradd(text5)
containeradd(text6)
containeradd(text7)
containeradd(name)
containeradd(c1)
containeradd(c2)
containeradd(c3)
containeradd(c4)
containeradd(c5)
containeradd(c6)
containeradd(c7)
containersetBackground(ColorlightGray)
containersetLayout(null)
setVisible(true)
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE)
}
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
facnamesearchgetText()
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is)}
Statement stmt
ResultSet rs
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
String drivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
rs(ResultSet)stmtexecuteQuery(select * from factory )
while(rsnext())
{
if(rsgetString(2)equals(facname))
{
text1setText(rsgetString(1))
text2setText(rsgetString(2))
text3setText(rsgetString(3))
text4setText(rsgetString(4))
text5setText(+(rsgetInt(5)))
text6setText(+rsgetInt(6))
text7setText(+rsgetInt(7))
}
}
rsclose()
stmtclose()
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
private class ButtonactionPerformed2 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Systemexit(0)
}
}
private class ButtonactionPerformed3 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
insert app3new insert()
app3setLocationRelativeTo(null)
}
}
private class ButtonactionPerformed4 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
delect app4new delect()
app4setLocationRelativeTo(null)
}
}
private class ButtonactionPerformed5 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
update app5new update()
app5setLocationRelativeTo(null)
}
}
private class ButtonactionPerformed6 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
create app6new create()
app6setLocationRelativeTo(null)
}
}
public static void main(String[] args)
{
operate appnew operate()
appsetLocationRelativeTo(null)
}
}
附录13 operate2代码
import javaawtColor
import javaawtContainer
import javaawteventActionEvent
import javaawteventActionListener
import javasqlConnection
import javasqlDriverManager
import javasqlSQLException
import javaxswingJButton
import javaxswingJFrame
import javaxswingJLabel
import javaxswingJTextField
import javaxswingUIManager
import javasqlResultSet
import javasqlStatement
public class operate2 extends JFrame
{
private static final long serialVersionUID 1L
private JButton b1b2b3b4
private JLabel c1c2c3c4c5c6c7d1d2d3d4
private JTextField text1text2text3text4text5text6text7ce1ce2ce3ce4
private JTextField search1search2
private JLabel namename2action1action2
private String facname1facname2
public operate2()
{
super(operate2)
setSize(700600)
try
{
UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName())
}catch(Exception e){}
Container containergetContentPane()
action1new JLabel( 查客户资料JLabelRIGHT)
action2new JLabel( 查户资料JLabelRIGHT)
namenew JLabel(输入企业名JLabelRIGHT)
c1new JLabel(企业编号JLabelRIGHT)
c2new JLabel(企业名称JLabelRIGHT)
c3new JLabel(企业代表JLabelRIGHT)
c4new JLabel(企业联系电话JLabelRIGHT)
c5new JLabel(企业谷电量JLabelRIGHT)
c6new JLabel(企业峰电费JLabelRIGHT)
c7new JLabel(企业电费JLabelRIGHT)
name2new JLabel(输入职工名JLabelRIGHT)
d1new JLabel(职工编号JLabelRIGHT)
d2new JLabel(职工名称JLabelRIGHT)
d3new JLabel(职工密码JLabelRIGHT)
d4new JLabel(职工等级JLabelRIGHT)
b1new JButton(查询)
b2new JButton(取消)
b3new JButton(查询)
b4new JButton(取消)
text1new JTextField(200)
text2new JTextField(200)
text3new JTextField(200)
text4new JTextField(200)
text5new JTextField(200)
text6new JTextField(200)
text7new JTextField(200)
ce1new JTextField(200)
ce2new JTextField(200)
ce3new JTextField(200)
ce4new JTextField(200)
search1new JTextField(60)
search2new JTextField(60)
action1setBounds(20010 200 30)
action2setBounds(200300 200 30)
namesetBounds(80 50 100 30)
name2setBounds(80 330 100 30)
c1setBounds(80 100 100 30)
c2setBounds(80 130 100 30)
c3setBounds(80 160 100 30)
c4setBounds(80 190 100 30)
c5setBounds(80 220 100 30)
c6setBounds(80 250 100 30)
c7setBounds(80 280 100 30)
d1setBounds(80 360 100 30)
d2setBounds(80 390 100 30)
d3setBounds(80 420 100 30)
d4setBounds(80 450 100 30)
search1setBounds(200 50 100 25)
search2setBounds(200 330 100 25)
b1setBounds(370 526025)
b2setBounds(500526025)
b3setBounds(370 3326025)
b4setBounds(5003326025)
text1setBounds(20010035030)
text2setBounds(20013035030)
text3setBounds(20016035030)
text4setBounds(20019035030)
text5setBounds(20022035030)
text6setBounds(20025035030)
text7setBounds(20028035030)
ce1setBounds(20036035030)
ce2setBounds(20039035030)
ce3setBounds(20042035030)
ce4setBounds(20045035030)
ButtonactionPerformed buttonernew ButtonactionPerformed()
ButtonactionPerformed2 buttoner2new ButtonactionPerformed2()
ButtonactionPerformed3 buttoner3new ButtonactionPerformed3()
b1addActionListener(buttoner)
b2addActionListener(buttoner2)
b3addActionListener(buttoner3)
b4addActionListener(buttoner2)
containeradd(b1)
containeradd(b2)
containeradd(b3)
containeradd(b4)
containeradd(search1)
containeradd(search2)
containeradd(text1)
containeradd(text2)
containeradd(text3)
containeradd(text4)
containeradd(text5)
containeradd(text6)
containeradd(text7)
containeradd(ce1)
containeradd(ce2)
containeradd(ce3)
containeradd(ce4)
containeradd(name)
containeradd(name2)
containeradd(action1)
containeradd(action2)
containeradd(c1)
containeradd(c2)
containeradd(c3)
containeradd(c4)
containeradd(c5)
containeradd(c6)
containeradd(c7)
containeradd(d1)
containeradd(d2)
containeradd(d3)
containeradd(d4)
containersetBackground(ColorlightGray)
containersetLayout(null)
setVisible(true)
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE)
}
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
facname1search1getText()
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is)}
Statement stmt
ResultSet rs
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
String drivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
rs(ResultSet)stmtexecuteQuery(select * from factory )
while(rsnext())
{
if(rsgetString(2)equals(facname1))
{
text1setText(rsgetString(1))
text2setText(rsgetString(2))
text3setText(rsgetString(3))
text4setText(rsgetString(4))
text5setText(+(rsgetInt(5)))
text6setText(+rsgetInt(6))
text7setText(+rsgetInt(7))
}
}
rsclose()
stmtclose()
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
private class ButtonactionPerformed2 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Systemexit(0)
}
}
private class ButtonactionPerformed3 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
facname2search2getText()
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is)}
Statement stmt
ResultSet rs
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
String drivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
rs(ResultSet)stmtexecuteQuery(select * from worker )
while(rsnext())
{
if(rsgetString(2)equals(facname2))
{
ce1setText(+rsgetInt(1))
ce2setText(rsgetString(2))
ce3setText(rsgetString(3))
ce4setText(+rsgetInt(4))
}
}
rsclose()
stmtclose()
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
public static void main(String[] args)
{
operate2 addnew operate2()
addsetLocationRelativeTo(null)
}
}
附录14 insert代码
import javaawtColor
import javaawtContainer
import javaawteventActionEvent
import javaawteventActionListener
import javasqlConnection
import javasqlDriverManager
import javasqlSQLException
import javaxswingJButton
import javaxswingJFrame
import javaxswingJLabel
import javaxswingJTextField
import javaxswingUIManager
import javasqlPreparedStatement
public class insert extends JFrame
{
private static final long serialVersionUID 1L
private JButton b1b2
private JLabel c1c2c3c4c5c6c7name
private JTextField text1text2text3text4text5text6text7
private String x1x2x3x4x5x6x7
public insert()
{
super(insert)
setSize(700400)
try
{
UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName())
}catch(Exception e){}
Container containergetContentPane()
namenew JLabel( 请输入添客户相关资料JLabelRIGHT)
c1new JLabel(企业编号JLabelRIGHT)
c2new JLabel(企业名称JLabelRIGHT)
c3new JLabel(企业代表JLabelRIGHT)
c4new JLabel(企业联系电话JLabelRIGHT)
c5new JLabel(企业谷电量JLabelRIGHT)
c6new JLabel(企业峰电量JLabelRIGHT)
c7new JLabel(企业电费JLabelRIGHT)
b1new JButton(确定)
b2new JButton(取消)
text1new JTextField(200)
text2new JTextField(200)
text3new JTextField(200)
text4new JTextField(200)
text5new JTextField(200)
text6new JTextField(200)
text7new JTextField(200)
namesetBounds(240 10 200 30)
c1setBounds(80 60 100 30)
c2setBounds(80 90 100 30)
c3setBounds(80 120 100 30)
c4setBounds(80 150 100 30)
c5setBounds(80 180 100 30)
c6setBounds(80 210 100 30)
c7setBounds(80 240 100 30)
b1setBounds(250 2806025)
b2setBounds(4502806025)
text1setBounds(2006035030)
text2setBounds(2009035030)
text3setBounds(20012035030)
text4setBounds(20015035030)
text5setBounds(20018035030)
text6setBounds(20021035030)
text7setBounds(20024035030)
ButtonactionPerformed buttonernew ButtonactionPerformed()
ButtonactionPerformed2 buttoner2new ButtonactionPerformed2()
b1addActionListener(buttoner)
b2addActionListener(buttoner2)
containeradd(name)
containeradd(b1)
containeradd(b2)
containeradd(text1)
containeradd(text2)
containeradd(text3)
containeradd(text4)
containeradd(text5)
containeradd(text6)
containeradd(text7)
containeradd(c1)
containeradd(c2)
containeradd(c3)
containeradd(c4)
containeradd(c5)
containeradd(c6)
containeradd(c7)
containersetBackground(ColorlightGray)
containersetLayout(null)
setVisible(true)
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE)
}
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
x1text1getText()
x2text2getText()
x3text3getText()
x4text4getText()
x5text5getText()
x6text6getText()
x7text7getText()
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is
PreparedStatement prepstmt1
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
String drivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
prepstmt1(PreparedStatement) connprepareStatement(INSERT INTO factory(numfacnamerepnametelusefnumusegnumusemoney)
+VALUES())
prepstmt1setString(1 x1)
prepstmt1setString(2 x2)
prepstmt1setString(3 x3)
prepstmt1setString(4 x4)
prepstmt1setString(5 x5)
prepstmt1setString(6 x6)
prepstmt1setString(7 x7)
prepstmt1executeUpdate()
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
private class ButtonactionPerformed2 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
operate app4new operate()
app4setLocationRelativeTo(null)
}
}
public static void main(String[] args)
{
insert appnew insert()
appsetLocationRelativeTo(null)
}
}
附录15 delect代码
import javaawtColor
import javaawtContainer
import javaawteventActionEvent
import javaawteventActionListener
import javasqlConnection
import javasqlDriverManager
import javasqlSQLException
import javaxswingJButton
import javaxswingJFrame
import javaxswingJLabel
import javaxswingJTextField
import javaxswingUIManager
import javasqlStatement
public class delect extends JFrame
{
private static final long serialVersionUID 1L
private JButton b1b2
private JLabel c1name
private JTextField text1
private String x1
public delect()
{
super(delect)
setSize(700400)
try
{ UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName())
}catch(Exception e){}
Container containergetContentPane()
namenew JLabel( 请输入添删客户企业编号JLabelRIGHT)
c1new JLabel(企业编号JLabelRIGHT)
b1new JButton(确定)
b2new JButton(取消)
text1new JTextField(200)
namesetBounds(240 10 200 30)
c1setBounds(80 60 100 30)
b1setBounds(200 1506025)
b2setBounds(4501506025)
text1setBounds(2006035030)
ButtonactionPerformed buttonernew ButtonactionPerformed()
ButtonactionPerformed2 buttoner2new ButtonactionPerformed2()
b1addActionListener(buttoner)
b2addActionListener(buttoner2)
containeradd(name)
containeradd(b1)
containeradd(b2)
containeradd(text1)
containeradd(c1)
containersetBackground(ColorlightGray)
containersetLayout(null)
setVisible(true)
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE)
}
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
x1text1getText()
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is)}
Statement stmt
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
StringdrivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
stmtexecuteUpdate(delete from factory where num+x1)
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
private class ButtonactionPerformed2 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
operate app4new operate()
app4setLocationRelativeTo(null)
}
}
public static void main(String[] args)
{
delect appnew delect()
appsetLocationRelativeTo(null)
}
}
附录16 update代码
import javaawtColor
import javaawtContainer
import javaawteventActionEvent
import javaawteventActionListener
import javasqlConnection
import javasqlDriverManager
import javasqlSQLException
import javaxswingJButton
import javaxswingJFrame
import javaxswingJLabel
import javaxswingJTextField
import javaxswingUIManager
import javasqlPreparedStatement
public class update extends JFrame
{
private static final long serialVersionUID 1L
private JButton b1b2
private JLabel c1c3c2c4name
private JTextField text1text2text3text4
private String x1x2x3x4
public update()
{
super(update)
setSize(700400)
try
{
UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName())
}catch(Exception e){}
Container containergetContentPane()
namenew JLabel( 请输入添修改客户企业编号相关信息JLabelRIGHT)
c1new JLabel(企业编号JLabelRIGHT)
c2new JLabel(企业谷电量JLabelRIGHT)
c3new JLabel(企业峰电量JLabelRIGHT)
c4new JLabel(企业电费JLabelRIGHT)
b1new JButton(确定)
b2new JButton(取消)
text1new JTextField(200)
text2new JTextField(200)
text3new JTextField(200)
text4new JTextField(200)
namesetBounds(150 10 300 30)
c1setBounds(200 60 100 30)
c2setBounds(200 90 100 30)
c3setBounds(200 120 100 30)
c4setBounds(200 150 100 30)
b1setBounds(250 2106025)
b2setBounds(3502106025)
text1setBounds(3006010030)
text2setBounds(3009010030)
text3setBounds(30012010030)
text4setBounds(30015010030)
ButtonactionPerformed buttonernew ButtonactionPerformed()
ButtonactionPerformed2 buttoner2new ButtonactionPerformed2()
b1addActionListener(buttoner)
b2addActionListener(buttoner2)
containeradd(name)
containeradd(b1)
containeradd(b2)
containeradd(text1)
containeradd(text2)
containeradd(text3)
containeradd(text4)
containeradd(c1)
containeradd(c2)
containeradd(c3)
containeradd(c4)
containersetBackground(ColorlightGray)
containersetLayout(null)
setVisible(true)
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE)
}
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
x1text1getText()
x2text2getText()
x3text3getText()
x4text4getText()
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is)}
PreparedStatement prepstmt2
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
String drivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
prepstmt2(PreparedStatement) connprepareStatement(update factory set numusegnumusefnumusemoney where num)
prepstmt2setString(1 x1)
prepstmt2setString(2 x2)
prepstmt2setString(3 x3)
prepstmt2setString(4 x4)
prepstmt2setString(5 x1)
prepstmt2executeUpdate()
prepstmt2close()
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
private class ButtonactionPerformed2 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
operate app4new operate()
app4setLocationRelativeTo(null)
}
}
public static void main(String[] args)
{
update appnew update()
appsetLocationRelativeTo(null)
}
}
附录17 create代码
import javaawtColor
import javaawtContainer
import javaawteventActionEvent
import javaawteventActionListener
import javasqlConnection
import javasqlDriverManager
import javasqlSQLException
import javaxswingJButton
import javaxswingJFrame
import javaxswingJLabel
import javaxswingJTextField
import javaxswingUIManager
import javasqlResultSet
import javasqlStatement
import javaioPrintWriter
import javaioFileNotFoundException
public class create extends JFrame
{
private static final long serialVersionUID 1L
private JButton b1b6
private JLabel c1c2c3
private JTextField text1text2text3
private JTextField search
private JLabel name
private String facnamex1x2x3x4
public create()
{
super(create)
setSize(600400)
try
{
UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName())
}catch(Exception e){}
Container containergetContentPane()
namenew JLabel(输入企业名JLabelRIGHT)
c1new JLabel(企业谷电量JLabelRIGHT)
c2new JLabel(企业峰电量JLabelRIGHT)
c3new JLabel(企业电费JLabelRIGHT)
b1new JButton(查询)
b6new JButton(生成电费单)
text1new JTextField(200)
text2new JTextField(200)
text3new JTextField(200)
searchnew JTextField(60)
namesetBounds(80 50 100 30)
c1setBounds(80 100 100 30)
c2setBounds(80 130 100 30)
c3setBounds(80 160 100 30)
searchsetBounds(200 50 100 25)
b1setBounds(320 526025)
b6setBounds(230 20010025)
text1setBounds(20010018030)
text2setBounds(20013018030)
text3setBounds(20016018030)
ButtonactionPerformed buttonernew ButtonactionPerformed()
ButtonactionPerformed2 buttoner2new ButtonactionPerformed2()
b1addActionListener(buttoner)
b6addActionListener(buttoner2)
containeradd(b1)
containeradd(b6)
containeradd(search)
containeradd(text1)
containeradd(text2)
containeradd(text3)
containeradd(name)
containeradd(c1)
containeradd(c2)
containeradd(c3)
containersetBackground(ColorlightGray)
containersetLayout(null)
setVisible(true)
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE)
}
private class ButtonactionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
facnamesearchgetText()
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is)}
Statement stmt
ResultSet rs
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
String drivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
rs(ResultSet)stmtexecuteQuery(select * from factory )
while(rsnext())
{
if(rsgetString(2)equals(facname))
{
x1rsgetString(5)
x2rsgetString(6)
x3rsgetString(7)
text1setText(rsgetString(5))
text2setText(rsgetString(6))
text3setText(rsgetString(7))
}
}
rsclose()
stmtclose()
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
private class ButtonactionPerformed2 implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
try
{
x4searchgetText()
PrintWriter fnew PrintWriter (C户Administrator桌面电费单txt)
fprintln( +x4+企业电费单 )
fprintln( )
fprintln( )
fprintln( 谷电量 +x1)
fprintln( )
fprintln( 峰电量 +x2)
fprintln( )
fprintln( 企业电费 +x3)
fclose()
}
catch(FileNotFoundException e)
{
Systemoutprintln(发生异常)
}
}
}
public static void main(String[] args)
{
create appnew create()
appsetLocationRelativeTo(null)
}
}
附录18 test代码
import javasqlConnection
import javasqlDriverManager
import javasqlSQLException
import javasqlResultSet
import javasqlStatement
public class test {
public test(){
try
{
ClassforName(driver)
}
catch(ClassNotFoundException arg0)
{
Systemoutprint(class not find exception occur message is)
}
try{
ClassforName(driver)加载驱动
}
catch(ClassNotFoundException event){Systemoutprint(class not find exception occur message is)}
Statement stmt
ResultSet rs
String urljdbcsqlserverlocalhost1433 DatabaseName企业电
String drivercommicrosoftsqlserverjdbcSQLServerDriver
String usersa
String password123456
Connection connnull
try
{
connDriverManagergetConnection(url user password)
connsetAutoCommit(true)
Systemoutprintln(数库已建立连接)
stmt(Statement) conncreateStatement()
int a1000
rs(ResultSet)stmtexecuteQuery(select * from worker )
while(rsnext())
{
if(rsgetInt(1)a) Systemoutprintln(数库连接成功)
}
rsclose()
stmtclose()
connclose()
}
catch(SQLException eb)
{
Systemoutprint(SQL exception occur message is)
Systemoutprint(ebgetMessage())
}
}
}
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档