课程实训报告书
目 录
1 实训目的.................................................................................................1
2 宿舍管理系统的分析与数据库设计.................................................. 1
2.1 系统功能描述.............................................................................1
2.2 系统模块分析.............................................................................1
2.3 数据库结构设计.........................................................................2
3 主要代码清单.......................................................................................2
4 程序运行与测试.................................................................................10
5 实训总结............................................................................................. 11
…
…
…
…
…
…
…
…
…
…
…
装
…
…
…
…
…
…
…
…
…
…
…
…
…
…
订
…
…
…
…
…
…
…
…
…
…
…
…
…
线
…
…
…
…
…
…
…
…
…
…
…
1
课程实训报告书
宿舍管理系统的设计与实现
1 实训目的
《基础项目实训》是计算机专业一门重要的专业技术基础实践课程。为了
能够较好的完成实训任务,学生应具备基础的软件开发技术和数据库的基础知
识,实训的主要目的在于将理论与实际应用相结合,使用程序设计语言 java 和
数据库技术,以及相关软件设计开发知识完成软件的设计开发任务。本实
训课程 将为整个专业的学习以及软件设计水平的提高打下良好的基础,提高学
生项目分 析、设计、编写、调试和测试的能力,并培养基本的、良好的团队合
作能力。
2 宿舍管理系统的分析与数据库设计
2.1 系统功能描述
为宿舍管理人员编写一个宿舍管理查询软件,提供公寓基本情况、寝室基本
情况、学生基本情况和卫生检查基本情况的分类管理和快速查询功能………
2.2 系统模块分析
(1)将学生住宿情况以及宿舍卫生情况存放在数据库中
(2)用 JAVA 编程--链接数据库
(3)通过 JAVA 与数据库的链接实现对学生住宿情况和个宿舍卫生的查询。
1
课程实训报告书
2.3 数据库结构设计
(本部分中要包含 E-R 图,数据字典,表结构等内容);
图表的格式如下所示:
m
宿舍
查询
n
学生
图 1 宿舍管理局部 E-R 图
3 主要代码清单
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.naming.*;
public class DBUtil {
private String url = "jdbc:mysql://127.0.0.1:3306/test1";
2
private String drivername = "com.mysql.jdbc.Driver";
private String dbuser = "root";
private String dbpass = "123";
private Connection con;
private Statement stmt;
private ResultSet rs;
public DBUtil() {
}
// 得到连接
public Connection getConnection() throws Exception {
if (con == null) {
// 加载驱动程序,参数是驱动程序的名字
Class.forName(drivername);
// 建立连接,第一个参数是 url,
// 第二个是用户名,第三个参数是口令
con = DriverManager.getConnection(url, dbuser, dbpass);
}
return con;
}
// 执行有结果集返回的 sql 语句
public ResultSet executeQuery(String sql) throws Exception {
if (con == null)
throw new Exception("没有连接对象可用");
// 创建语句对象
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
return rs;
}
// 执行更新语句
public int executeUpdate(String sql) throws Exception {
if (con == null)
throw new Exception("没有连接可用");
// 创建语句对象
stmt = con.createStatement();
// 执行 sql 语句
return stmt.executeUpdate(sql);
}
public void close() {
try {
if (rs != null)
rs.close();
} catch (Exception e) {
}
try {
stmt.close();
} catch (Exception e) {
}
try {
con.close();
} catch (Exception e) {
}
}
}
class test implements ActionListener{
public static Tux t;
public static void main(String[] args) throws Exception{
t = new Tux();
db.executeUpdate("update a1 set a2='3' where id='3'");
}
CallableStatement cs=con.prepareCall("{call proc1(?)}");
cs.registerOutParameter(1, java.sql.Types.TINYINT);
cs.execute();
System.out.println(cs.getInt(1));
//
/*
*/
static void bb6() throws Exception
{
String str0=t.test4.getText();
String str2=t.test5.getText();
// int st=IntegerInt(str);
DBUtil db=new DBUtil();
Connection con=db.getConnection();
String str1="update student set name='"+str2+"' where xuehao="+str0+"";
int rs=db.executeUpdate(str1);
/*while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.setText("学号"+rs.getString(1)+" 姓名"+rs.getString(2)+" 班级"+rs.getString(3)+" 房号
"+rs.getString(4)+" 床号"+rs.getString(5));
}
*/
}
static void bb7() throws Exception
{
String str0=t.test4.getText();
String str2=t.test5.getText();
// int st=IntegerInt(str);
DBUtil db=new DBUtil();
Connection con=db.getConnection();
String str1="update student set class='"+str2+"' where xuehao="+str0+"";
int rs=db.executeUpdate(str1);
/*while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.setText("学号"+rs.getString(1)+" 姓名"+rs.getString(2)+" 班级"+rs.getString(3)+" 房号
"+rs.getString(4)+" 床号"+rs.getString(5));
}
*/
}
static void bb8() throws Exception
{
String str0=t.test4.getText();
String str2=t.test5.getText();
// int st=IntegerInt(str);
DBUtil db=new DBUtil();
Connection con=db.getConnection();
String str1="update student set fanghao="+str2+" where xuehao="+str0+"";
int rs=db.executeUpdate(str1);
/*while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.setText("学号"+rs.getString(1)+" 姓名"+rs.getString(2)+" 班级"+rs.getString(3)+" 房号
"+rs.getString(4)+" 床号"+rs.getString(5));
}
*/
}
static void bb1() throws Exception
{
String str0=t.test1.getText();
// int st=IntegerInt(str);
DBUtil db=new DBUtil();
Connection con=db.getConnection();
String str1="select * from student where name='"+str0+"'";
ResultSet rs=db.executeQuery(str1);
while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.setText(" 学 号 "+rs.getString(1)+" 姓 名 "+rs.getString(2)+" 班 级 "+rs.getString(3)+" 房 号
"+rs.getString(4)+" 床号"+rs.getString(5));
}
}
static void bb2() throws Exception
{
String str=t.test1.getText();
// int st=IntegerInt(str);
DBUtil db=new DBUtil();
Connection con=db.getConnection();
String str1="select * from student where xuehao="+str+"";
ResultSet rs=db.executeQuery(str1);
while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.setText(" 学 号 "+rs.getString("xuehao")+" 姓 名 "+rs.getString("name")+" 班 级
"+rs.getString("class")+" 房号"+rs.getString("fanghao")+" 床号"+rs.getString("chuanghao"));
}
}
static void bb3() throws Exception
{
String str=t.test1.getText();
// int st=IntegerInt(str);
DBUtil db=new DBUtil();
Connection con=db.getConnection();
String str1="select * from student where class='"+str+"'";
ResultSet rs=db.executeQuery(str1);
while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.setText(" 学 号 "+rs.getString("xuehao").trim()+" 姓 名 "+rs.getString("name").trim()+" 班 级
号
"+rs.getString("fanghao").trim()+"
号
床
"+rs.getString("class").trim()+"
房
"+rs.getString("chuanghao").trim()+"\n");
while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.append("学号"+rs.getString("xuehao").trim()+" 姓名"+rs.getString("name").trim()+" 班
号
"+rs.getString("fanghao").trim()+"
房
号
床
"+rs.getString("class").trim()+"
级
"+rs.getString("chuanghao").trim()+"\n");
}
}
}
static void bb4() throws Exception
{
String str=t.test1.getText();
// int st=IntegerInt(str);
DBUtil db=new DBUtil();
Connection con=db.getConnection();
String str1="select * from student where fanghao="+str+"";
ResultSet rs=db.executeQuery(str1);
while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.setText("学号"+rs.getString("xuehao").trim()+" 姓名"+rs.getString("name").trim()+" 班
号
"+rs.getString("fanghao").trim()+"
房
号
床
"+rs.getString("class").trim()+"
级
"+rs.getString("chuanghao").trim()+"\n");
while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.append("
"+rs.getString("xuehao").trim()+"
名
"+rs.getString("name").trim()+" 班级"+rs.getString("class").trim()+" 房号"+rs.getString("fanghao").trim()+" 床
号"+rs.getString("chuanghao").trim()+"\n");
学
号
姓
}
static void bb5() throws Exception
}
}
{
String str0=t.test2.getText();
String str2=t.test3.getText();
// int st=IntegerInt(str);
DBUtil db=new DBUtil();
Connection con=db.getConnection();
String str1="select * from weisheng where zhou="+str0+" and fanghao="+str2+"";
ResultSet rs=db.executeQuery(str1);
while(rs.next()){
//System.out.println(rs.getString(1)+"*"+rs.getString(2)+"*"+rs.getString(3));
t.test6.append("房号"+rs.getString("fanghao").trim()+"周数"+rs.getString("zhou").trim()+"
卫生情况"+rs.getString("qk").trim()+"\n");
}
}
{
static void bb9() throws Exception