




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
完美WORD格式.整理分享.完美WORD格式整理分享数据库课程实训报告<2015--2016年度第2学期>题目:企业用电管理系统专业软件工程学生姓名成晓伟班级软件141学号1410075094指导教师徐静完成日期2016.7.1完美WORD格式..完美WORD格式目录TOC\o"1-5"\h\z\u目录21课题内容和要求11.1课题描述11.2课题要求12需求分析12.1对功能的规定12.2数据需求分析23系统设计33.1功能模块设计33.2数据库概念设计43.2.2E-R图43.3数据库逻辑设计53.4数据库物理设计53.5数据库表间联系64系统实现64.1登陆模块实现64.2查询模块实现74.3添加模块实现84.4删除模块实现94.5修改模块实现104.6生成电费单模块实现105代码调试与功能测试115.1测试方案115.2测试结果126收获与体会16参考文献17附录18附录1源程序部分清单18..企业用电管理系统设计1课题内容和要求1.1课题描述系统设计的的信息有:用电企业〔用电企业编号、用电企业名、地址、电话、联系人;电费信息〔谷价、峰价;用电情况〔用电企业编号、谷电量、峰电量、年月、年合计用电量、年合计用电费。1.2课题要求要求能够进行如下操作:能够统计各个用电企业的月耗电量以及电费;能够统计查询各个用电企业的总的谷电量和峰电量;能够统计该地区的峰谷电量比例以及电费情况;能维护基本数据;用户分级管理,人机界面良好。2需求分析2.1对功能的规定1、理解需求理解需求是在问题及其最终解决方案之间架设桥梁的第一步。开发者只有和用户充分理解了需求之后才能开始设计系统,否则,对需求定义的任何改进,设计上都必须大量的返工。下面是对系统的终端用户和客户调研后得到的需求规格说明书。<1>由于使用者为相关电力部门及学习使用,系统开始时,便可以进入到欢迎界面。<2>进入到系统之后,友好的界面可以很清晰的分为企业信息管理跟企业用电信息管理两大选择。<3>点击企业信息管理,下拉菜单中选项可以实现对企业信息的查询、添加、修改、删除操作。<4>点击企业用电管理信息,下拉菜单中选项可以实现对企业用电管理信息的查询、添加、修改和删除操作。<5>系统客户端运行在Windows平台下,服务器可以运行在Windows或Unix平台下。系统还应该有一个较好的图形用户界面。<6>系统应该有很好的可扩展性。2、需求分析需求分析是从客户的需求中提取出软件系统能够帮助用户解决的业务问题,通过对用户业务问题的分析,确定系统的功能需求。这个步骤是对理解需求的升华,直接关系到该系统的质量。分析的根本目的是在开发者和提出需求的人之间建立一种理解和沟通机制,因此,系统的需求分析也应该是开发人员和用户或客户一起完成的。2.2对性能的规定1、精度在精度需求上,根据使用需要,在各项数据的输入,输出及传输过程中,可以满足各种精度的需求。如:根据关键字精度的不同,查找可分为精确查找和泛型查找,精确查找可精确匹配系统使用者所知道的企业名称及编号快速便捷的查询所要知道的信息。2、时间特性要求在软件方面,响应时间,更新处理时间都比较快且迅速,完全满足用户要求。3、灵活性当用户需求,如操作方式,运行环境,结果精度,数据结构于其他软件接口等发生变化时,设计的软件要做适当调整,灵活性非常大。2.2数据需求分析数据字典〔1factory名称:factory名称:factory别名:无描述:企业的基本信息组成:factory=〔num+facname+repname+tel+usefnum+usegnum+usemoney<2>worker名称:worker名称:worker别名:无描述:员工及管理员的基本信息组成:worker=〔id+workername+password+level3系统设计3.1功能模块设计3.2数据库概念设计3.2.1实体属性图3.2.2E-R图3.3数据库逻辑设计企业〔编号,企业名,法人代表电价〔峰电量,谷电量,峰电价,谷电价,总电费系统用户〔编号,姓名,密码,权限3.4数据库物理设计表一:factory列名数据类型允许Null值numvarchar<50>是facnamevarchar<50>是repnamevarchar<50>是telvarchar<50>是usefnumint是usegnumint是usemoneyint是numfacnamerepnametelusefnumusegnumusemoney001新华书店陈国勇131410222333002苏果超市陈博文151622532863003微软公司毕世勇368524674952004乐天玛特丁小杰301127943105005三厂中学陈家勇242219742875表二:worker列名数据类型允许Null值idint否workernamevarchar<50>否passwordvarchar<50>否[level]int否idworkernamepassword[level]111张三1234561112李四1234561113熊大1234562114熊二12345623.5数据库表间联系数据库中所建的两张表factory与worker之间并没有任何直接的联系,一个代表的是企业信息,一个代表的是员工信息。4系统实现4.1登陆模块实现privateclassButtonactionPerformedimplementsActionListener//为登陆按钮ButtonactionPerformed添加事件监视器{publicvoidactionPerformed<ActionEvente>//从worker表中获得元组信息进行登陆,下面为获得元组登陆代码 { a=username2.getText<>; s=password2.getText<>;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; stmt=<Statement>conn.createStatement<>; rs=<ResultSet>stmt.executeQuery<"select*fromworker">;if<c.equals<a>&&b.equals<s>> { message.setText<"姓名和密码不能为空">; }elseif<true> {while<rs.next<>> {if<rs.getString<2>.equals<a>&&rs.getString<3>.equals<s>&&rs.getInt<4>==level> { message.setText<"数据库连接成功!">;if<level==1> { operate2app2=newoperate2<>; app2.setLocationRelativeTo<null>; }else { operateapp3=newoperate<>; app3.setLocationRelativeTo<null>; } }else { message.setText<"用户名和密码或者身份不正确">; } } } rs.close<>; stmt.close<>; conn.close<>; }4.2查询模块实现privateclassButtonactionPerformedimplementsActionListener//为查询按钮ButtonactionPerformed添加事件监视器 {publicvoidactionPerformed<ActionEvente>//从worker表中获取元组,并且显示在系统上 { facname=search.getText<>;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; stmt=<Statement>conn.createStatement<>; rs=<ResultSet>stmt.executeQuery<"select*fromfactory">;while<rs.next<>> {if<rs.getString<2>.equals<facname>> { text1.setText<rs.getString<1>>; text2.setText<rs.getString<2>>; text3.setText<rs.getString<3>>; text4.setText<rs.getString<4>>; text5.setText<""+<rs.getInt<5>>>; text6.setText<""+rs.getInt<6>>; text7.setText<""+rs.getInt<7>>; } } rs.close<>; stmt.close<>; conn.close<>; }4.3添加模块实现privateclassButtonactionPerformedimplementsActionListener//为添加按钮ButtonactionPerformed添加事件监视器 {publicvoidactionPerformed<ActionEvente>//在系统内输入要添加的元组信息,通过添加按钮添加到数据库中的factory表内 { x1=text1.getText<>; x2=text2.getText<>; x3=text3.getText<>; x4=text4.getText<>; x5=text5.getText<>; x6=text6.getText<>; x7=text7.getText<>;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; prepstmt1=<PreparedStatement>conn.prepareStatement<"INSERTINTOfactory<num,facname,repname,tel,usefnum,usegnum,usemoney>" +"VALUES<?,?,?,?,?,?,?>">; prepstmt1.setString<1,x1>; prepstmt1.setString<2,x2>; prepstmt1.setString<3,x3>; prepstmt1.setString<4,x4>; prepstmt1.setString<5,x5>; prepstmt1.setString<6,x6>; prepstmt1.setString<7,x7>; prepstmt1.executeUpdate<>; conn.close<>; }4.4删除模块实现privateclassButtonactionPerformedimplementsActionListener {publicvoidactionPerformed<ActionEvente> { x1=text1.getText<>;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; stmt=<Statement>conn.createStatement<>; stmt.executeUpdate<"deletefromfactorywherenum="+x1>; conn.close<>; }4.5修改模块实现privateclassButtonactionPerformedimplementsActionListener {publicvoidactionPerformed<ActionEvente> { x1=text1.getText<>; x2=text2.getText<>; x3=text3.getText<>; x4=text4.getText<>;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; prepstmt2=<PreparedStatement>conn.prepareStatement<"updatefactorysetnum=?,usegnum=?,usefnum=?,usemoney=?wherenum=?">; prepstmt2.setString<1,x1>; prepstmt2.setString<2,x2>; prepstmt2.setString<3,x3>; prepstmt2.setString<4,x4>; prepstmt2.setString<5,x1>; prepstmt2.executeUpdate<>; prepstmt2.close<>; conn.close<>; }4.6生成电费单模块实现privateclassButtonactionPerformedimplementsActionListener {publicvoidactionPerformed<ActionEvente> { facname=search.getText<>;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; stmt=<Statement>conn.createStatement<>; rs=<ResultSet>stmt.executeQuery<"select*fromfactory">;while<rs.next<>> {if<rs.getString<2>.equals<facname>> { x1=rs.getString<5>; x2=rs.getString<6>; x3=rs.getString<7>; text1.setText<rs.getString<5>>; text2.setText<rs.getString<6>>; text3.setText<rs.getString<7>>; } } rs.close<>; stmt.close<>; conn.close<>; }5代码调试与功能测试5.1测试方案〔1分别输入用户、管理员查看登陆进去后的界面〔2分别用用户和管理员查询企业用电信息〔3添加企业用电信息〔4修改企业用电信息〔5删除企业用电信息〔6生成电费单5.2测试结果管理员登陆管理员登陆后的界面管理员登陆后查询的界面用户登陆后查询的界面点击添加后的界面输入数据添加成功点击修改进行修改信息修改成功点击删除后出现的界面删除成功点击生成电费单出现的界面在桌面生成的电费单6收获与体会一、这次课程设计的心得体会通过实践我的收获如下:一开始接触数据结构课程设计真的挺难的,好多都不会,不是逻辑方面的问题,而不具备动手能力,脑子里总有一团火,比如对于这个题目,一开始有很多的想法,想到了从逻辑上怎么实现他,要编写哪些程序,但是一到需要编写了就开始为难了,可以说是几乎不知道从哪里入手,参考了书本里的程序,仿照他的结构一步一步做下来,现在对于单链表的各种操作已经算是比较熟练了,但我知道光有理论知识还远远不够,需要多动手,写的多了自然就能手到擒来。二、根据我在实习中遇到得问题,我将在以后的学习过程中注意以下几点:1、认真上好专业实验课,多在实践中锻炼自己。2、写程序的过程中要考虑周到,严密。3、在做设计的时候要有信心,有耐心,切勿浮躁。4、认真的学习课本知识,掌握课本中的知识点,并在此基础上学会灵活运用。5、在课余时间里多写程序,熟练掌握在调试程序的过程中所遇到的常见错误,以便能节省调试程序的时间。..参考文献[1]钱雪忠,王燕玲,林挺.数据库原理及技术[M].北京:清华大学出版社,2011.[2]钱雪忠,罗海驰,陈国俊.数据库原理及技术课程设计[M].北京:清华大学出版社,2014.附录附录1源程序部分清单附录1.1record代码importjava.awt.*;importjava.awt.event.*;importjava.sql.Connection;importManager;importjava.sql.SQLException;importjava.sql.ResultSet;importjava.sql.Statement;importjavax.swing.*;publicclassRecordextendsJFrame{privatestaticfinallongserialVersionUID=1L;privateJLabelusername,password;privateJTextFieldusername2;privateJTextFieldpassword2,message;privateJButtonbutton;privateJRadioButtonbox1,box2;privateButtonGroupbuttongroup;privateStringa,s;privateStringc="";privateStringb="";privateintlevel=2; //privateStringjuzi;publicRecord<> {super<"Record">; setSize<300,300>;try { UIManager.setLookAndFeel<UIManager.getSystemLookAndFeelClassName<>>; }catch<Exceptione>{} Containercontainer=getContentPane<>; container.setBackground<Color.lightGray>; container.setLayout<null>; username=newJLabel<"用户名:",JLabel.RIGHT>; password=newJLabel<"密码:",JLabel.RIGHT>; buttongroup=newButtonGroup<>; box1=newJRadioButton<"员工",true>; box2=newJRadioButton<"管理员">; username2=newJTextField<20>; password2=newJTextField<20>; message=newJTextField<"欢迎使用企业用电管理系统">; message.setHorizontalAlignment<JTextField.CENTER>; button=newJButton<"登录">; username.setBounds<50,50,50,25>; username2.setBounds<100,50,120,25>; password.setBounds<50,85,50,25>; password2.setBounds<100,85,120,25>; message.setBounds<55,160,190,25>; box1.setBounds<50,120,50,25>; box2.setBounds<110,120,70,25>; button.setBounds<190,120,60,25>; buttongroup.add<box1>; buttongroup.add<box2>; ButtonactionPerformedbuttoner=newButtonactionPerformed<>; button.addActionListener<buttoner>; RadioButtonHandlerhandler=newRadioButtonHandler<>; box1.addItemListener<handler>; box2.addItemListener<handler>; container.add<username>; container.add<username2>; container.add<password>; container.add<password2>; container.add<box1>; container.add<box2>; container.add<button>; container.add<message>; setVisible<true>; setDefaultCloseOperation<JFrame.EXIT_ON_CLOSE>; }publicstaticvoidmain<String[]args> { Record app=newRecord<>; app.setLocationRelativeTo<null>; }privateclassRadioButtonHandlerimplementsItemListener {publicvoiditemStateChanged<ItemEventevent> {if<box1.isSelected<>> { message.setText<"员工登录">; level=2; }elseif<box2.isSelected<>> { message.setText<"管理员登录">; level=1; } } }privateclassButtonactionPerformedimplementsActionListener {publicvoidactionPerformed<ActionEvente>//登录 { a=username2.getText<>; s=password2.getText<>;try { Class.forName<"driver">; }catch<ClassNotFoundExceptionarg0> { System.out.print<"classnotfindexceptionoccur.messageis:">; }try{ Class.forName<"driver">;//加载驱动 }catch<ClassNotFoundExceptionevent>{System.out.print<"classnotfindexceptionoccur.messageis:">;} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企业用电"; Stringdriverc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; stmt=<Statement>conn.createStatement<>; rs=<ResultSet>stmt.executeQuery<"select*fromworker">;if<c.equals<a>&&b.equals<s>> { message.setText<"姓名和密码不能为空">; }elseif<true> {while<rs.next<>> {if<rs.getString<2>.equals<a>&&rs.getString<3>.equals<s>&&rs.getInt<4>==level> { message.setText<"数据库连接成功!">;if<level==1> { operate2app2=newoperate2<>; app2.setLocationRelativeTo<null>; }else { operateapp3=newoperate<>; app3.setLocationRelativeTo<null>; } }else { message.setText<"用户名和密码或者身份不正确">; } } }rs.close<>; stmt.close<>; conn.close<>; }catch<SQLExceptioneb> { System.out.print<"SQLexceptionoccur.messageis:">; System.out.print<eb.getMessage<>>; } } }}附录1.2operate代码importjava.awt.Color;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importnager;importjava.sql.SQLException;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importjavax.swing.UIManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassoperateextendsJFrame{privatestaticfinallongserialVersionUID=1L;privateJButtonb1,b2,b3,b4,b5,b6;privateJLabelc1,c2,c3,c4,c5,c6,c7;privateJTextFieldtext1,text2,text3,text4,text5,text6,text7;privateJTextFieldsearch;privateJLabelname;privateStringfacname;publicoperate<> {super<"operate">; setSize<700,400>;try { UIManager.setLookAndFeel<UIManager.getSystemLookAndFeelClassName<>>; }catch<Exceptione>{} Containercontainer=getContentPane<>; name=newJLabel<"输入企业名:",JLabel.RIGHT>; c1=newJLabel<"企业编号:",JLabel.RIGHT>; c2=newJLabel<"企业名称:",JLabel.RIGHT>; c3=newJLabel<"企业代表人:",JLabel.RIGHT>; c4=newJLabel<"企业联系电话:",JLabel.RIGHT>; c5=newJLabel<"企业谷电量:",JLabel.RIGHT>; c6=newJLabel<"企业峰电量:",JLabel.RIGHT>; c7=newJLabel<"企业用电费:",JLabel.RIGHT>; b1=newJButton<"查询">; b2=newJButton<"取消">; b3=newJButton<"添加">; b4=newJButton<"删除">; b5=newJButton<"修改">; b6=newJButton<"生成电费单">; text1=newJTextField<200>; text2=newJTextField<200>; text3=newJTextField<200>; text4=newJTextField<200>; text5=newJTextField<200>; text6=newJTextField<200>; text7=newJTextField<200>; search=newJTextField<60>; name.setBounds<80,50,100,30>; c1.setBounds<80,100,100,30>; c2.setBounds<80,130,100,30>; c3.setBounds<80,160,100,30>; c4.setBounds<80,190,100,30>; c5.setBounds<80,220,100,30>; c6.setBounds<80,250,100,30>; c7.setBounds<80,280,100,30>; search.setBounds<200,50,100,25>; b1.setBounds<370,52,60,25>; b2.setBounds<500,52,60,25>; b3.setBounds<150,330,60,25>; b4.setBounds<250,330,60,25>; b5.setBounds<350,330,60,25>; b6.setBounds<450,330,100,25>; text1.setBounds<200,100,350,30>; text2.setBounds<200,130,350,30>;text3.setBounds<200,160,350,30>; text4.setBounds<200,190,350,30>; text5.setBounds<200,220,350,30>; text6.setBounds<200,250,350,30>; text7.setBounds<200,280,350,30>; ButtonactionPerformedbuttoner=newButtonactionPerformed<>; ButtonactionPerformed2buttoner2=newButtonactionPerformed2<>; ButtonactionPerformed3buttoner3=newButtonactionPerformed3<>; ButtonactionPerformed4buttoner4=newButtonactionPerformed4<>; ButtonactionPerformed5buttoner5=newButtonactionPerformed5<>; ButtonactionPerformed6buttoner6=newButtonactionPerformed6<>; b1.addActionListener<buttoner>; b2.addActionListener<buttoner2>; b3.addActionListener<buttoner3>; b4.addActionListener<buttoner4>; b5.addActionListener<buttoner5>; b6.addActionListener<buttoner6>; container.add<b1>; container.add<b2>; container.add<b3>; container.add<b4>; container.add<b5>; container.add<b6>; container.add<search>; container.add<text1>; container.add<text2>; container.add<text3>; container.add<text4>; container.add<text5>; container.add<text6>; container.add<text7>; container.add<name>; container.add<c1>; container.add<c2>; container.add<c3>; container.add<c4>; container.add<c5>; container.add<c6>; container.add<c7>; container.setBackground<Color.lightGray>; container.setLayout<null>; setVisible<true>; setDefaultCloseOperation<JFrame.EXIT_ON_CLOSE>; }privateclassButtonactionPerformedimplementsActionListener {publicvoidactionPerformed<ActionEvente> { facname=search.getText<>;try { Class.forName<"driver">; }catch<ClassNotFoundExceptionarg0> { System.out.print<"classnotfindexceptionoccur.messageis:">; }try{ Class.forName<"driver">;//加载驱动 }catch<ClassNotFoundExceptionevent>{System.out.print<"classnotfindexceptionoccur.messageis:">;} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企业用电"; Stringdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; stmt=<Statement>conn.createStatement<>; rs=<ResultSet>stmt.executeQuery<"select*fromfactory">;while<rs.next<>> {if<rs.getString<2>.equals<facname>> { text1.setText<rs.getString<1>>; text2.setText<rs.getString<2>>; text3.setText<rs.getString<3>>; text4.setText<rs.getString<4>>; text5.setText<""+<rs.getInt<5>>>; text6.setText<""+rs.getInt<6>>; text7.setText<""+rs.getInt<7>>; } } rs.close<>; stmt.close<>; conn.close<>; }catch<SQLExceptioneb> { System.out.print<"SQLexceptionoccur.messageis:">; System.out.print<eb.getMessage<>>; } } }privateclassButtonactionPerformed2implementsActionListener {publicvoidactionPerformed<ActionEventevent> { System.exit<0>; } }privateclassButtonactionPerformed3implementsActionListener {publicvoidactionPerformed<ActionEventevent> { insertapp3=newinsert<>; app3.setLocationRelativeTo<null>; } }privateclassButtonactionPerformed4implementsActionListener {publicvoidactionPerformed<ActionEventevent> { delectapp4=newdelect<>; app4.setLocationRelativeTo<null>; } }privateclassButtonactionPerformed5implementsActionListener {publicvoidactionPerformed<ActionEventevent> { updateapp5=newupdate<>; app5.setLocationRelativeTo<null>; } }privateclassButtonactionPerformed6implementsActionListener {publicvoidactionPerformed<ActionEventevent> { createapp6=newcreate<>; app6.setLocationRelativeTo<null>; } }publicstaticvoidmain<String[]args> { operateapp=newoperate<>; app.setLocationRelativeTo<null>; }}附录1.3operate2代码importjava.awt.Color;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importjavax.swing.UIManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassoperate2extendsJFrame{privatestaticfinallongserialVersionUID=1L;privateJButtonb1,b2,b3,b4;privateJLabelc1,c2,c3,c4,c5,c6,c7,d1,d2,d3,d4;privateJTextFieldtext1,text2,text3,text4,text5,text6,text7,ce1,ce2,ce3,ce4;privateJTextFieldsearch1,search2;privateJLabelname,name2,action1,action2;privateStringfacname1,facname2;publicoperate2<> {super<"operate2">; setSize<700,600>;try { UIManager.setLookAndFeel<UIManager.getSystemLookAndFeelClassName<>>; }catch<Exceptione>{} Containercontainer=getContentPane<>; action1=newJLabel<"查看客户的资料",JLabel.RIGHT>; action2=newJLabel<"查看用户的资料",JLabel.RIGHT>; name=newJLabel<"输入企业名:",JLabel.RIGHT>; c1=newJLabel<"企业编号:",JLabel.RIGHT>; c2=newJLabel<"企业名称:",JLabel.RIGHT>; c3=newJLabel<"企业代表人:",JLabel.RIGHT>; c4=newJLabel<"企业联系电话:",JLabel.RIGHT>; c5=newJLabel<"企业谷电量:",JLabel.RIGHT>; c6=newJLabel<"企业峰电费:",JLabel.RIGHT>; c7=newJLabel<"企业用电费:",JLabel.RIGHT>; name2=newJLabel<"输入职工名:",JLabel.RIGHT>; d1=newJLabel<"职工编号:",JLabel.RIGHT>; d2=newJLabel<"职工名称:",JLabel.RIGHT>; d3=newJLabel<"职工密码:",JLabel.RIGHT>; d4=newJLabel<"职工等级:",JLabel.RIGHT>; b1=newJButton<"查询">; b2=newJButton<"取消">; b3=newJButton<"查询">; b4=newJButton<"取消">; text1=newJTextField<200>; text2=newJTextField<200>; text3=newJTextField<200>; text4=newJTextField<200>; text5=newJTextField<200>; text6=newJTextField<200>; text7=newJTextField<200>; ce1=newJTextField<200>; ce2=newJTextField<200>; ce3=newJTextField<200>; ce4=newJTextField<200>; search1=newJTextField<60>; search2=newJTextField<60>; action1.setBounds<200,10,200,30>; action2.setBounds<200,300,200,30>; name.setBounds<80,50,100,30>; name2.setBounds<80,330,100,30>; c1.setBounds<80,100,100,30>; c2.setBounds<80,130,100,30>; c3.setBounds<80,160,100,30>; c4.setBounds<80,190,100,30>; c5.setBounds<80,220,100,30>; c6.setBounds<80,250,100,30>; c7.setBounds<80,280,100,30>; d1.setBounds<80,360,100,30>; d2.setBounds<80,390,100,30>; d3.setBounds<80,420,100,30>; d4.setBounds<80,450,100,30>; search1.setBounds<200,50,100,25>; search2.setBounds<200,330,100,25>; b1.setBounds<370,52,60,25>; b2.setBounds<500,52,60,25>; b3.setBounds<370,332,60,25>; b4.setBounds<500,332,60,25>; text1.setBounds<200,100,350,30>; text2.setBounds<200,130,350,30>; text3.setBounds<200,160,350,30>; text4.setBounds<200,190,350,30>; text5.setBounds<200,220,350,30>; text6.setBounds<200,250,350,30>; text7.setBounds<200,280,350,30>; ce1.setBounds<200,360,350,30>; ce2.setBounds<200,390,350,30>; ce3.setBounds<200,420,350,30>; ce4.setBounds<200,450,350,30>; ButtonactionPerformedbuttoner=newButtonactionPerformed<>; ButtonactionPerformed2buttoner2=newButtonactionPerformed2<>; ButtonactionPerformed3buttoner3=newButtonactionPerformed3<>; b1.addActionListener<buttoner>; b2.addActionListener<buttoner2>; b3.addActionListener<buttoner3>; b4.addActionListener<buttoner2>; container.add<b1>; container.add<b2>; container.add<b3>; container.add<b4>; container.add<search1>; container.add<search2>; container.add<text1>; container.add<text2>; container.add<text3>; container.add<text4>; container.add<text5>; container.add<text6>; container.add<text7>; container.add<ce1>; container.add<ce2>; container.add<ce3>; container.add<ce4>; container.add<name>; container.add<name2>; container.add<action1>; container.add<action2>; container.add<c1>; container.add<c2>; container.add<c3>; container.add<c4>; container.add<c5>; container.add<c6>; container.add<c7>; container.add<d1>; container.add<d2>; container.add<d3>; container.add<d4>; container.setBackground<Color.lightGray>; container.setLayout<null>; setVisible<true>; setDefaultCloseOperation<JFrame.EXIT_ON_CLOSE>; }privateclassButtonactionPerformedimplementsActionListener {publicvoidactionPerformed<ActionEvente> { facname1=search1.getText<>;try { Class.forName<"driver">; }catch<ClassNotFoundExceptionarg0> { System.out.print<"classnotfindexceptionoccur.messageis:">; }try{ Class.forName<"driver">;//加载驱动 }catch<ClassNotFoundExceptionevent>{System.out.print<"classnotfindexceptionoccur.messageis:">;} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企业用电"; Stringdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; stmt=<Statement>conn.createStatement<>; rs=<ResultSet>stmt.executeQuery<"select*fromfactory">;while<rs.next<>> {if<rs.getString<2>.equals<facname1>> { text1.setText<rs.getString<1>>; text2.setText<rs.getString<2>>; text3.setText<rs.getString<3>>; text4.setText<rs.getString<4>>; text5.setText<""+<rs.getInt<5>>>; text6.setText<""+rs.getInt<6>>; text7.setText<""+rs.getInt<7>>; } } rs.close<>; stmt.close<>; conn.close<>; }catch<SQLExceptioneb> { System.out.print<"SQLexceptionoccur.messageis:">; System.out.print<eb.getMessage<>>; } } }privateclassButtonactionPerformed2implementsActionListener {publicvoidactionPerformed<ActionEventevent> { System.exit<0>; } }privateclassButtonactionPerformed3implementsActionListener {publicvoidactionPerformed<ActionEvente> { facname2=search2.getText<>;try { Class.forName<"driver">; }catch<ClassNotFoundExceptionarg0> { System.out.print<"classnotfindexceptionoccur.messageis:">; }try{ Class.forName<"driver">;//加载驱动 }catch<ClassNotFoundExceptionevent>{System.out.print<"classnotfindexceptionoccur.messageis:">;} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企业用电"; Stringdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null;try { conn=DriverManager.getConnection<url,user,password>; conn.setAutoCommit<true>; System.out.println<"和数据库已经建立连接!!!">; stmt=<Statement>conn.createStatement<>; rs=<ResultSet>stmt.executeQuery<"select*fromworker">;while<rs.next<>> {if<rs.getString<2>.equals<facname2>> { ce1.setText<""+rs.getInt<1>>; ce2.setText<rs.getString<2>>; ce3.setText<rs.getString<3>>; ce4.setText<""+rs.getInt<4>>; } } rs.close<>; stmt.close<>; conn.close<>; }catch<SQLExceptioneb> { System.out.print<"SQLexceptionoccur.messageis:">; System.out.print<eb.getMessage<>>; } } }publicstaticvoidmain<String[]args> { operate2add=newoperate2<>; add.setLocationRelativeTo<null>; }}附录1.4insert代码importjava.awt.Color;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;import
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 自动化股票交易创新创业项目商业计划书
- 养殖水产品标准化生产流程创新创业项目商业计划书
- 职业教育课程跨界融合创新创业项目商业计划书
- 护士三基考试题及答案
- 文化艺术展览组织和保障措施
- 地铁工程项目管理措施
- 七年级下册英语节日祝福作文范文
- 新入职员工积极分子培养考察意见范文
- 2025版农药生产项目投资合作合同范本
- 2025年度道路施工土方车运输及清运合同
- 农资货运运输管理办法
- 2025至2030全球及中国过敏原提取物行业产业运行态势及投资规划深度研究报告
- 物业基础培训课件
- 人教版九年级上册历史期末复习知识点考点背诵提纲详细版
- 2025年广东省中考英语真题(原卷版)
- 捐资奖学金活动方案
- 非标自动化培训
- 2025年贵州省中考化学试卷真题(含答案解析)
- 高桩码头施工培训课件
- 2025至2030中国工业混合式步进电机行业发展趋势分析与未来投资战略咨询研究报告
- 《大学体育理论与实践教程》大学体育课程全套教学课件
评论
0/150
提交评论