码迷,mamicode.com
首页 > 其他好文 > 详细

课程 教师 教室

时间:2017-11-28 19:50:04      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:rman   setattr   iat   jdb   drive   ror   不同的   resultset   ack   

  1. 设计思想

定义三个信息,连接数据库,输入用户信息。

    1. 源程序代码
    2. 截图
技术分享图片
package bean;

public class Ms {
    String classname;
    String place;
    String teacher;
    public String getClassname() {
        return classname;
    }
    public void setClassname(String classname) {
        this.classname = classname;
    }
    public String getPlace() {
        return place;
    }
    public void setPlace(String place) {
        this.place = place;
    }
    public String getTeacher() {
        return teacher;
    }
    public void setTeacher(String teacher) {
        this.teacher = teacher;
    }
    

}
View Code
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import bean.Ms;
import util.DButil;

public class classMs {
    
    public void add(Ms  ms)
    {
        //获得链接对象
                Connection connection = DButil.getConnection();
                //创建语句传输对象
                PreparedStatement preparedStatement = null;
                try {
                
                    
                    String sql = "insert into kc_msg (classname,teacher,place) value (?,?,?)";
                    preparedStatement = connection.prepareStatement(sql);
                    preparedStatement.setString(1, ms.getClassname());
                    preparedStatement.setString(2,ms.getTeacher());
                    preparedStatement.setString(3,ms.getPlace());
                    
                    preparedStatement.executeUpdate();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }finally {
                    //关闭资源
                    DButil.close(connection);
                }
        
    }
    
    
    

}
技术分享图片
package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DButil {
    public static Connection getConnection()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (InstantiationException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
        String user="root";
        String password="root";
        String url = "jdbc:mysql://localhost:3306/jaovo_msg";
        Connection connection=null;
        try {
            connection=DriverManager.getConnection(url,user,password);
        } catch (SQLException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
        
        return connection;
    }
    
    public static void close(Connection connection)
    {
        try {
            connection.close();
        } catch (SQLException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }
    public static void close(PreparedStatement preparedStatement)
    {
        try {
            preparedStatement.close();
        } catch (SQLException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }
    public static void close(ResultSet resultSet)
    {
        try {
            resultSet.close();
        } catch (SQLException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }

}

package util;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

public class Exception {
    
    public static  boolean validateNull(HttpServletRequest request,String[] fileds) {
    
        boolean validate = true;
        //map对象用来装载不同的错误信息
        Map<String,String> errorMsg = new  HashMap();
        for(String filed :fileds) {
            String value = request.getParameter(filed);
            if (value == null || "".equals(value.trim())) {
                validate = false;
                errorMsg.put(filed, "不能为空!");
            }
            if (!validate) {
                request.setAttribute("errormsg", errorMsg);
            }
            
        }
        
        return validate;
    }
    public static String showError(HttpServletRequest request , String filed) {
        Map<String, String> errorMsg = (Map<String,String>)request.getAttribute("errormsg");
        if (errorMsg == null) {
            return "";
        }
        String msg = errorMsg.get(filed);
        if (msg == null) {
            return "";
        }
        return msg;
    }

}
View Code
技术分享图片
<%@page import="java.util.Map"%>
<%@page import="util.Exception"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加课程</title>
</head>
<body>
<%Map<String,String> errorMs = (Map<String,String>)request.getAttribute("errorms"); 
%>
<form  action="saveInput.jsp" method="get">

<br>
<center > 课程名称:<input  type="text"  name="classname" /><%= Exception.showError(request, "classname") %></center>

<br>
<center > 任课教师:<input  type="text"  name="teacher" /><%= Exception.showError(request, "teacher") %></center>

<br>
<center > 上课地点:<input  type="text"  name="place" /><%= Exception.showError(request, "place") %></center>

<br>
<center><input type="submit" value="保存"  /> </center>
</form>

</body>
</html>
View Code
技术分享图片
<%@page import="util.Exception"%>
<%@page import="bean.Ms"%>
<%@page import="dao.classMs"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加课程</title>
</head>
<body>
<%
    //接收客户端传递过来的参数
    String classname = request.getParameter("classname");
    String teacher = request.getParameter("teacher");
    String place = request.getParameter("place");
    
    boolean validate = Exception.validateNull(request, new String[]{"classname","teacher","place"});
    if(!validate){
    
%>
<jsp:forward page="save.jsp"></jsp:forward>
<%
    }
    if(!place.startsWith("基教")&&!place.startsWith("一教")&&!place.startsWith("二教")&&!place.startsWith("三教"))
    {
        %>
        <script language=‘javaScript‘ > alert(‘没有这个教室\n请重新输入!‘);window.history.back(-1);</script>
        <% 
    }
    else if(!teacher.equals("王建民")&&!teacher.equals("刘立嘉")&&!teacher.equals("刘丹"))
    {
        %>
        <script language=‘javaScript‘ > alert(‘没有这个老师!\n请重新输入‘);window.history.back(-1);</script>
        <% 
    }
    else
    {
           Ms msg=new Ms();
           msg.setClassname(classname);
           msg.setTeacher(teacher);
           msg.setPlace(place);
           classMs cm=new classMs();
           cm.add(msg);    
    }    
    %>
    <center>保存成功!!<br></center>
    <center><a href="save.jsp">继续添加</a></center>
</body>
</html>
View Code
      1. 项目计划日历

时间

课堂测试

编写程序

总计

 

 

 

 

上午

50分钟

 

50分钟

下午

 

2个小时

120分钟

时间记录日历

日期

开始时间

中断时间

净时间

活动

备注

11.28

 

 

 

 

 

上午

9:00

9:50

50

编程

课堂测试

下午

1:00

3:00

120

编程

编程

 

缺陷记录日志

日期

编号

类型

引入阶段

排除阶段

修复时间

修复缺陷

11.28

1

 

 

 

5分钟

 

 

描述:无法传入数据库。

 

2

 

 

 

10分钟

 

 

描述:界面跳转不正确。

课程 教师 教室

标签:rman   setattr   iat   jdb   drive   ror   不同的   resultset   ack   

原文地址:http://www.cnblogs.com/wmy-666/p/7911560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!