数据库课程设计(java版)
更新时间:2023-08-30 14:17:01 阅读量: 教育文库 文档下载
- java数据库课程设计推荐度:
- 相关推荐
计算机科学与技术学院课程设计成绩单
优秀:90分~100分 良好:80分~89分 中等:70~79分 及格:60~69分 不及格0分~59分
计算机科学与技术学院
课 程
课程名称:专 业:班 级:学 号:姓 名:指导老师:设 计 报 告
数据库系统原理
java学生成绩管理系统课程设计报告以及代码共享
一、课程题目
设计一个简易的电子书店管理系统。用于记录书店书本的信息以供管理员管理。 (1) 记录书本的基本信息,如编号、名称、类型、作者等 (2) 记录各个读者的信息。
(3) 实现一些管理的基本功能,如:书本信息的查询、插入新的书本信息、更改 以及删除书本信息等功能。
(4) 能够连接数据库,从中获取信息。
二、题目分析与设计
1. 使用的开发环境。
我使用的开发环境是Eclipse,数据库是mysql。
2. 根据课题画出数据流程图。
电子书店管理,实现添加书本记录、修改书本记录,删除及更改记录的功能。
3. 根据课题画出E-R图。
4. 数据库中各个表的结构。
此次课题使用了三张表: 图书表(图书编号(主码),图书名,类型,作者,数目,价格); 读者表(读者编号(主码),读者名,年龄,性别,电话,地址); 订单表(订单编号(主码),图书编号,读者编号,数目,需付金额)。 5. 界面设计过程和组件的布局策略。
由多个界面组成,通过点击界面的按钮来响应下一个事务,并对操作的 失误有友好的提醒界面功能。 6. 论述程序逻辑的实现
用户输入数据后,整理数据,通过JDBC连接数据库进行各种操作。
三、测试分析
1. 登陆界面
进入登陆界面输入用户名:何耀武 密码:1234 点击确定就可以进入主界 面然后根据自己的需要点击界面上的操作按钮,从而进入下一个界面来实 现要完成的操作
主要代码如下:
jButton1.addActionListener(new ActionListener() {//确定按钮所产生的事务
public void actionPerformed(ActionEvent e) { try { if(e.getSource()==jButton1){ String S1="***",S2="1234";
if((jTextField1.getText()).equals(S1)&&jPasswordField1用户名密码比
{
dispose();
NewJFrame1 main_ui=new NewJFrame1(); main_ui.setVisible(true);
} else { jLabel4.setText("你输入的密码或用户名有误,请再输入" ); jLabel4.setVisible(true);
jPasswordField1.setText(null);//输入错误提示
}
}
} catch (Exception f) { f.printStackTrace(); } }
});
jButton1.addActionListener(new ActionListener() {//进入下个界面 public void actionPerformed(ActionEvent e) { if(e.getSource()==jButton1){ dispose(); NewJFrame2 N2=new NewJFrame2(); N2.setVisible(true);//出现主界面
} }
});
jButton3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub
if(e.getSource()==jButton3){ dispose(); NewJFrame6 N6=new NewJFrame6();
N6.setVisible(true);//出现主界面
});
}
}
2. 测试结果 (1)查询书本信息
进入查询界面后点击要查询的对象,然后在方框内输入编号点击确 定按钮从而得到所要查询的信息。
主要查询代码:
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { String S=null;
if(jRadioButton1.isSelected()) { jTextField2.setText(null); if(e.getSource()==jButton1) S=jTextField1.getText();
String driver="com.mysql.jdbc.Driver";//驱动程序 String url = "jdbc:mysql://localhost:3306/sellbook"; String user="root";//登录名 String password="118157439";//密码 Connection Conn = null;//l连接数据库 try{
Class.forName(driver); Conn=DriverManager.getConnection(url,user,password); String query = "select * from books where Bno='"+S+"';"; PreparedStatement ps=Conn.prepareStatement(query); ResultSet result = ps.executeQuery(); NewJFrame3 n3=new NewJFrame3(); while (result.next()) { n3.jTextField1.setText(result.getString("Bno")); n3.jTextField2.setText(result.getString("Bname")); n3.jTextField3.setText(result.getString("Btype")); n3.jTextField4.setText(result.getString("Bauthor")); n3.jTextField5.setText(result.getString("Bprice")); n3.jTextField6.setText(result.getString("Bnumber")); ");
}//查询所得数据
if(n3.jTextField1.getText().length()==0)
{ IOS_ron N1=new IOS_ron(null); N1.setVisible(true); }//查询编号不在,计算机报错
else {
//dispose(); n3.setVisible(true); Conn.close(); } } catch(SQLException f) {
//JOptionPane.showMessageDialog(null, "输入有误
}
f.printStackTrace(); }
catch(Exception g){ g.printStackTrace(); }
if(jRadioButton2.isSelected())//点击第二个按钮的操作实现
{ jTextField1.setText(null); if(e.getSource()==jButton1) S=jTextField2.getText();
String driver="com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/sellbook"; String user="root";
String password="528157439"; Connection Conn = null; try{
Class.forName(driver);//驱动加载
Conn=DriverManager.getConnection(url,user,password);
");
String query = "select * from orders where Ono='"+S+"';"; PreparedStatement ps=Conn.prepareStatement(query); ResultSet result = ps.executeQuery(); NewJFrame4 n4=new NewJFrame4();//选择数据 while (result.next()) { n4.jTextField1.setText(result.getString("Ono")); n4.jTextField2.setText(result.getString("Bno")); n4.jTextField3.setText(result.getString("Rno")); n4.jTextField4.setText(result.getString("Onumber")); n4.jTextField5.setText(result.getString("Opay"));
}//查询所得数据
if(n4.jTextField1.getText().length()==0)
{ IOS_ron N1=new IOS_ron(null); N1.setVisible(true);
}//报错处理
else {
n4.setVisible(true); Conn.close(); }} catch(SQLException f) {
JOptionPane.showMessageDialog(null, "输入有误
} catch (Exception f) {
f.printStackTrace(); } } }});
(2)插入书本信息
点击插入按钮进入插入界面,向对话框中输入信息,如: 009 大学音乐 音乐 30 李红 10
将这一组数据插入表中,然后点击确定按钮,会弹出对话框插入成功, 表明数据插入成功。 主要插入代码:
jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(jTextField1.getText().length()==0){
jLabel8.setText("编号不能为空" );//判断插入编号不能为空 jLabel8.setVisible(true); }
if(jTextField1.getText().length()!=0){ String driver="com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/sellbook"; String user="root"; String password="118157439";
Connection Conn = null;//连接数据库
try{
Class.forName(driver);//加载驱动
Conn=DriverManager.getConnection(url,user,password);
String query = "insert into books values(?,?,?,?,?,?)"; //连接数据库,向其中插入数据
PreparedStatement ps=Conn.prepareStatement(query); ps.setString(1, jTextField1.getText()); ps.setString(2, jTextField2.getText()); ps.setString(3, jTextField3.getText()); ps.setString(4, jTextField4.getText()); ps.setString(5, jTextField5.getText()); ps.setString(6, jTextField6.getText());
ps.executeUpdate();//插入成功 Conn.close();//关闭连接
}
catch(ClassNotFoundException f)
});
}
}
{ System.out.println(f.getMessage()); }
catch(SQLException g){ System.out.println(g.getMessage()); }
add_suc a=new add_suc(null); a.setVisible(true);
(3)修改书本信息
在主界面点击要修改图书信息,输入要修改的图书信息,进入图书修改界面, 在对话框中修改所要修改的信息,如: 价格:由30修改为46,数目:由10修改为4.
之后点击确定按钮,弹出对话框更改成功,即完成更改。
修改代码为:
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { if(e.getSource()==jButton1){
String driver="com.mysql.jdbc.Driver";//加载驱动 String url = "jdbc:mysql://localhost:3306/sellbook"; String user="root";//用户名 String password="118157439";//密码 Connection Conn = null;//连接数据库
try{
Class.forName(driver);
Conn=DriverManager.getConnection(url,user,password); String query = "delete from books where Bno='"+jTextField1.getText()+"'"; PreparedStatement ps=Conn.prepareStatement(query); ps.executeUpdate();
String query1 = "insert into books values(?,?,?,?,?,?)";//插入 PreparedStatement ps2=Conn.prepareStatement(query1); ps2.setString(1, jTextField1.getText()); ps2.setString(2, jTextField2.getText()); ps2.setString(3, jTextField3.getText()); ps2.setString(4, jTextField5.getText()); ps2.setString(5, jTextField4.getText()); ps2.setString(6, jTextField6.getText());
});
} }
ps2.executeUpdate();//更改成功 Conn.close();//关闭连接
}
catch(ClassNotFoundException f) { System.out.println(f.getMessage()); }
catch(SQLException g){ System.out.println(g.getMessage()); }
alter_suc a=new alter_suc(null); a.setVisible(true);//弹出更改成功窗口
(4)删除图书信息
进入删除图书界面,输入图书编号,点击确定按钮,当弹出删除成功 对话窗口,即成功删除,这样实现删除要删除的图书信息。
删除代码为:
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { String S=jTextField1.getText(); try { String driver="com.mysql.jdbc.Driver";//加载驱动 String url = "jdbc:mysql://localhost:3306/sellbook"; String user="root";//用户名
String password="118157439";//密码 Connection Conn = null;//连接数据库 Class.forName(driver); Conn=DriverManager.getConnection(url,user,password); String query = "delete from books where Bno='"+S+"'"; //删除图书信息 PreparedStatement ps=Conn.prepareStatement(query); ps.executeUpdate();//删除成功 Conn.close(); delete_suc d=new delete_suc(null); d.setVisible(true);//弹出删除成功的对话框 }catch(ClassNotFoundException f) {
System.out.println("Message="+f.getMessage()); } catch(SQLException g){ g.printStackTrace(); }
}});
四、总结
不足之处:
(1)对于这个课题的实践,界面做的过多,应该设计为一个界面上完成各个操 作,弹出窗口过多,不易观察,过于复杂。
(2)所做的操作由于技术有限,能够实现的功能太少,要加强软件的实用性, 操作不能太单一。
(3)程序写的不是很完善,存在许多漏洞,需要通过以后的学习不断的加一 巩固和改善。 可取之处:
(1)基本上完成了题目的要求,实现了查询,插入,更新,删除数据的操作, 可以满足要求。
(2)完成了对数据完整性约束的要求,但用户输入错误时会有一个比较好的的 弹出框提醒用户,比较人性化。 实践心得:
通过此次为期三周的数据库实践课题,确实学到了不少的东西,通过连接 数据库,从中获得数据,体现数据库数据结构化,数据独立,易于扩充 的特点,对JAVA这门以面向对象为主体的操作语言有了进一步的加深 加熟了对这门语言的认知。这次的实践对自己以后的学习有很积极的指导 作用。
正在阅读:
数据库课程设计(java版)08-30
瑞斯康达ONU设备互通配置指导手册(20090531) - 图文10-03
高中地理 世界地理 东亚 东南亚 南亚教学案一体化 鲁教版09-11
2018-2019年七年级语文上册第五单元16猫导学案新人教版12-06
苏州市直属单位和局(公司)工会干部轮训班开卷作业题目03-04
上海市2015届12校高三12月联考英语试题及答案11-18
吉他自学入门教程07-27
有关沟通的重要性的日记作文03-12
平淡的网名02-15
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 课程
- 数据库
- 设计
- java
- 走近劳动保障 欢迎登陆重庆劳动保障网站
- 电力系统调度自动化第7章 EMS(3)-网络拓扑
- 2017年长春师范大学数学学院333教育综合之外国教育史教程考研题库
- 超级飞侠涂色画
- 酒店与婚庆公司战略合作提案
- 中国瑜伽教练培训产业现状调查及未来五年投资价值分析报告
- 特殊病种申请
- 小功率伺服无刷直流电机驱动器设计
- 金融学形成性考核作业(仅供参考)
- 中国不允许乱(一九八九年三月四日)
- 弱电施工组织设计方案
- 劳动者权益保障法论文
- Unit 10 Make your choice
- 商业建筑的人流系统规划分析
- 国际品牌酒店财务部服务流程与规范
- 新材料企业对接资本市场的四大障碍
- 总体规划与概念建筑设计咨询服务合同书20101027
- OTC业务员业务市场调查报告
- 犯罪学精讲第四章
- 入党演讲稿(入党积极分子发言)