zoukankan      html  css  js  c++  java
  • 第三周进度报告(拼团系统项目)

    相关代码以及数据库文件:
    Coding地址

    已实现模块

    成功连接到数据库。正确显示数据库内容。本次完成的主要是对数据库中活动的列表展示。

    主要代码

    • 实验环境

    Eclipse EE + mysql

    • 连接数据库,主要是通过连接池来实现:

    package pintuan.db;
    import java.sql.*;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
    public class DBPool {
    	private String jndiName = "java:comp/env/jdbc/pintuan";
    	private Connection conn = null;
    	public DBPool() {
    		
    	}
    	public DBPool(String jndiName){
    		this.jndiName = jndiName;
    	}
    	public Connection getConnection(){
    		try {
    			InitialContext context = new InitialContext();
    			DataSource ds = (DataSource) context.lookup(jndiName);
    			conn = ds.getConnection();
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return conn;
    	}
    	public ResultSet doQueryRS(String sql, Object[] params) throws SQLException {
    		conn = this.getConnection();
    		PreparedStatement pstmt = conn.prepareStatement(sql);
    		for (int i = 0; i < params.length; i++) {
    			pstmt.setObject(i + 1, params[i]);
    		}
    		ResultSet rs = pstmt.executeQuery();
    		
    		return rs;
    	}
    	public int doUpdate(String sql,Object[]params) throws SQLException{
    		conn = this.getConnection();
    		int res = 0;
    		PreparedStatement pstmt = conn.prepareStatement(sql);
    		for (int i = 0; i < params.length; i++) {
    			pstmt.setObject(i+1, params[i]);
    		}
    		res = pstmt.executeUpdate();
    		this.close();
    		return res;
    	}
    	public void close(){
    		if(conn!=null){
    			try {
    				conn.close();
    			} catch (SQLException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    	}
    
    }
    
    
    • 其次编写的EventThreads类(相关的getter(),setter()方法这里不展示,都贴上来页面不友好):

    package pintuan.bean;
    
    import java.sql.Time;
    import java.sql.Timestamp;
    
    public class EventThreads {
    
    	private int EventID;
    	private String EventName;
    	private String EventType;
    	private String EventInitiator;
    	private int UserID;
    	private Time StarTime;
    	private Time EndTime;
    	private Time SignEndTime;
    	private Timestamp DateCreated;
    	private String Location;
    	private String Body;
    	private int HitTimes;
    	private int memberCount;
    	private int LimitCount;
    
    
    • 编写相关DAO接口以及实现接口:

    package pintuan.dao;
    import java.util.List;
    import pintuan.bean.EventThreads;
    public interface EventThreadsDAO {
    	/*
    	 * 
    	 * 获取所有的活动
    	 */
    	public abstract List<EventThreads> getEventThreads() throws Exception;
    	/*
    	 * 
    	 * 根据活动类型获得活动
    	 */
    	public abstract List<EventThreads> getEventByType(String Type) throws Exception;
    	
    }
    
    
    package pintuan.dao;
    
    import java.awt.Event;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    import pintuan.bean.EventThreads;
    import pintuan.db.DBPool;
    
    public class EventThreadsDaoImpl implements EventThreadsDAO {
    
    	@Override
    	public List<EventThreads> getEventThreads() throws Exception {
    		List<EventThreads> e_list = null;
    		ResultSet rs = null;
    		DBPool dbc = new DBPool();	
    		e_list = new ArrayList<EventThreads>();
    		String sql = "select*from pt_eventthreads";
    		rs = dbc.doQueryRS(sql, new Object[]{});
    		while(rs.next()){
    			System.out.println(rs.getInt("EventID"));
    			EventThreads event = new EventThreads();
    			event.setEventID(rs.getInt("EventID"));
    			event.setEventName(rs.getString("EventName"));
    			event.setEventType(rs.getString("EventType"));
    			event.setEventInitiator(rs.getString("EventInitiator"));
    			event.setUserID(rs.getInt("UserID"));
    			event.setStarTime(rs.getTime("StartTime"));
    			event.setEndTime(rs.getTime("EndTime"));
    			event.setSignEndTime(rs.getTime("SignEndTime"));
    			event.setDateCreated(rs.getTimestamp("DateCreated"));
    			event.setLocation(rs.getString("Location"));
    			event.setBody(rs.getString("Body"));
    			event.setMemberCount(rs.getInt("MemberCount"));
    			event.setLimitCount(rs.getInt("LimitCount"));
    			
    			e_list.add(event);
    		}
    		dbc.close();
    		return e_list;
    	}
    
    	@Override
    	public List<EventThreads> getEventByType(String type) throws Exception {
    		List<EventThreads> e_list = null;
    		ResultSet rs = null;
    		DBPool dbc = new DBPool();	
    		e_list = new ArrayList<EventThreads>();
    		String sql = "select *from pt_eventthreads where EventType=?";
    		rs = dbc.doQueryRS(sql, new Object[]{type});
    		while(rs.next()){
    			EventThreads event = new EventThreads();
    			event.setEventID(rs.getInt("EventID"));
    			event.setEventName(rs.getString("EventName"));
    			event.setEventType(rs.getString("EventType"));
    			event.setEventInitiator(rs.getString("EventInitiator"));
    			event.setUserID(rs.getInt("UserID"));
    			event.setStarTime(rs.getTime("StartTime"));
    			event.setEndTime(rs.getTime("EndTime"));
    			event.setSignEndTime(rs.getTime("SignEndTime"));
    			event.setDateCreated(rs.getTimestamp("DateCreated"));
    			event.setLocation(rs.getString("Location"));
    			event.setBody(rs.getString("Body"));
    			event.setMemberCount(rs.getInt("MemberCount"));
    			event.setLimitCount(rs.getInt("LimitCount"));
    			
    			e_list.add(event);
    		}
    		dbc.close();
    		return e_list;
    	}
    }
    
    
    • 最后编写一个showEvent.jsp用于测试,数据是否能正确传递,正确显示:

    <%@page import="pintuan.bean.EventThreads"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        <%@page import = "pintuan.db.*" %>
        <%@page import = "pintuan.dao.*" %>
        <%@page import = "java.util.*" %>
    <!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>Insert title here</title>
    </head>
    <body>
    <%
        DBPool dbc = new DBPool();
        EventThreadsDAO eventDAO = new EventThreadsDaoImpl();
        List<EventThreads> results = new ArrayList<EventThreads>();
        results = eventDAO.getEventThreads(); 
    %>
    <table border="1">
    <td>发起人ID</td> <td>发起人</td> <td>活动名称</td> <td>活动内容</td> <td>活动类型</td>
      <td>活动开始时间</td><td>活动结束时间</td><td>活动发布时间</td><td>活动地点</td><td>限制人数</td>
    <%
        for(int i = 0;i<results.size();i++){
        	EventThreads event = results.get(i);
        	
    %>
    <tr>
      
        <td><%=event.getUserID()%></td>
        <td><%=event.getEventInitiator() %></td>
        <td><%=event.getEventName() %></td>
        <td><%=event.getBody() %></td>
        <td><%=event.getEventType() %></td>
        <td><%=event.getStarTime() %></td>
        <td><%=event.getEndTime() %></td>
        <td><%=event.getDateCreated() %></td>
        <td><%=event.getLocation() %></td>
        <td><%=event.getLimitCount() %></td>
    </tr>
    <%} %>
    </table>
    </body>
    </html>
    
    • 运行截图:

    小结反馈

    • Servlet掌握得不是很熟练,所以这次没有用到,是一个大缺陷。但是个人认为一步一步来,不要太心急。
    • JSP页面这块由小组中的另外两个成员负责,所以这次的jsp页面只是用于测试(不美观是一定的,要是就这样面向用户我肯定取关拉黑)
    • 文档没有写好,这次做的过程中,我有尝试写一个需求分析,试图建立一个框架,但是失败了。一个方面是时间来不及,另一方面是用例图想用UML来画,结果花了一个钟头去研究,还是没搞清楚。
    • 目前自己有建立起一个大体的框架,但是我觉得跟团队成员的沟通不是很多,但是在没有沟通的情况下我和团队成员竟然一个写了用户管理,一个写了活动管理。。。也是默契十足。接下来要改变的是交流这个习惯,我知道我之前做的不是很好。
    • 这周的任务完成的还行,前两周的任务没写,第一周是刚开始建博客,我们讨论清楚哪些功能队长发布内容。第二周我的工作量比较少,主要是把数据库建起来(但是数据库的表于表的关联没做清楚),但是缺了进度报告。第三周,我觉得这样下去不是办法,然后度过了充实的一周。(图书馆偷电少女)

    新一周计划

    • 把相关步骤代码写个博客,让团队成员更好交接。
    • 学习Servlet,改进代码。
  • 相关阅读:
    html实体引用
    nginx配置奇怪问题记录
    20191025-生产事故记录
    abp审计日志功能的关闭
    mysql根据一张表更新另一张表数据
    redis-cli连接redis服务器操作
    错误记录-MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired.
    UID,GID,口令
    【搬砖】/etc/passwd 文件结构
    《图形学》实验五:改进的Bresenham算法画直线
  • 原文地址:https://www.cnblogs.com/shizhuangde/p/6585601.html
Copyright © 2011-2022 走看看