数据库课程设计easymall电子商城大学论文.docx

上传人:b****1 文档编号:2190406 上传时间:2023-05-02 格式:DOCX 页数:25 大小:1.02MB
下载 相关 举报
数据库课程设计easymall电子商城大学论文.docx_第1页
第1页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第2页
第2页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第3页
第3页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第4页
第4页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第5页
第5页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第6页
第6页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第7页
第7页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第8页
第8页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第9页
第9页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第10页
第10页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第11页
第11页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第12页
第12页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第13页
第13页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第14页
第14页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第15页
第15页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第16页
第16页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第17页
第17页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第18页
第18页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第19页
第19页 / 共25页
数据库课程设计easymall电子商城大学论文.docx_第20页
第20页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

数据库课程设计easymall电子商城大学论文.docx

《数据库课程设计easymall电子商城大学论文.docx》由会员分享,可在线阅读,更多相关《数据库课程设计easymall电子商城大学论文.docx(25页珍藏版)》请在冰点文库上搜索。

数据库课程设计easymall电子商城大学论文.docx

数据库课程设计easymall电子商城大学论文

淮海工学院计算机工程学院

课程设计报告

设计名称:

《数据库课程设计》

选题名称:

EasyMall电子商城

姓名:

学号:

专业班级:

系(院):

计算机工程学院

设计时间:

设计地点:

指导教师评语:

 

签名:

年月日

1.课程设计目的

熟悉掌握MySQL,MyEclipse软件的应用,巩固数据库中所学的知识,结合J2EE内容,将数据库中的数据与myEclipse相连接。

初步了解有关大数据的知识,利用所学知识来设计一个easymall商城,实现商城的登录注册,加入购物车,查看商品信息等功能。

通过实践来经历一个数据库系统开发的全过程并受到一次综合的训练,以便能较全面的理解、掌握和综合运用所学的知识去分析、解决实际问题。

 

2.课程设计任务与要求:

课程设计任务:

完成《easymall商城》系统的分析设计工作,并选用适当的开发工具完成系统的开发。

课程设计要求:

实现

商城的主页面

商品详细信息展示

商品加入购物车

商品订单查询

商品的查询

用户的注册、登录、注销

 

3.课程设计说明书

(1)流程图

 

(2)在mysql中建立表:

(主键id)

商品表products

用来存储

商品的名字:

name

商品的价格:

price

商品的类型:

category

商品的编号:

pumn

商品的图片地址:

imgurl

商品的描述:

description

 

订单表orders(主键id)

用来存储

订单的价格:

money

收货人地址:

receiverinfo

付款状态:

paystate

付款时间:

ordertime

订单用户id:

user_id

用户表user(主键id)

用来存储

用户的姓名:

username

用户的密码:

password

用户的昵称:

nickname

用户的昵称:

nickname

用户的邮件:

email

用户的身份:

role

订单项目表:

orderitem(主键order_id,product_id)

各个表之间的关系

(3)在myEclipse中编写代码,实现网页功能

项目目录

java类

cn.tedu.dao包

ProfDao.java查询符合条件的商品集合

package cn.tedu.dao;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

import org.apache.taglibs.standard.tag.rt.core.ForEachTag;

import cn.tedu.utils.JdbcUtil;

import cn.tedu.vo.Product;

public class ProdDao {

Connection conn = null;

PreparedStatement pstat =null;

ResultSet rs = null;

/**根据查询条件,查询符合条件的商品集合

 * @param name 商品名称

 * @param category:

商品分类

 * @param minprice:

价格区间的最小值

 * @param maxprice:

价格区间的最大值

 * @return 查询符合条件的商品集合List

 */

public List findProdsByKey(String name, String category,

double minprice, double maxprice) {

//1、创建一个商品的集合对象

List list = new ArrayList();

//3、定义三个全局变量(数据库连接的)

//4、编写sql语句

String sql = "select * from products where name like ?

 and category like ?

 and price>=?

 and price<=?

";

try {

//5、获取数据库连接对象

conn = JdbcUtil.getConn();

//6、预编译sql语句

pstat = conn.prepareStatement(sql);

//7、为占位符赋值

pstat.setString(1, "%"+name+"%");

pstat.setString(2, "%"+category+"%");

pstat.setDouble(3, minprice);

pstat.setDouble(4, maxprice);

//8、执行查询操作

rs = pstat.executeQuery();

//9处理结果集

while(rs.next()){

Product prod = new Product();

prod.setId(rs.getString("id"));

prod.setName(rs.getString("name"));

prod.setPrice(rs.getDouble("price"));

prod.setPnum(rs.getInt("pnum"));

prod.setImgurl(rs.getString("imgurl"));

prod.setCategory(rs.getString("category"));

prod.setDescription(rs.getString("category"));

list.add(prod);

}

} catch (SQLException e) {

e.printStackTrace();

}finally{

JdbcUtil.close(conn, pstat, rs);

}

//2、返回集合对象

return list;

}

/**根据商品的id查询商品的详细信息

 * @param id:

商品的id

 * @return 该id对应的商品详情对象

 */

public Product findProdById(String id) {

String sql = "select * from products where id = ?

";

//获取数据库连接

conn = JdbcUtil.getConn();

try {

//预编译sql语句,并返回pstat

pstat = conn.prepareStatement(sql);

//为占位符赋值

pstat.setString(1, id);

//执行查询,并返回结果集

rs = pstat.executeQuery();

//处理结果集合

if(rs.next()){

Product prod = new Product();

prod.setId(rs.getString("id"));

prod.setName(rs.getString("name"));

prod.setImgurl(rs.getString("imgurl"));

prod.setPnum(rs.getInt("pnum"));

prod.setCategory(rs.getString("category"));

prod.setPrice(rs.getDouble("price"));

prod.setDescription(rs.getString("description"));

return prod;

}

} catch (SQLException e) {

e.printStackTrace();

}finally{

JdbcUtil.close(conn,pstat,rs);

}

return null;

}

}

UserDao.java查询符合条件的用户集合

package cn.tedu.dao;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import cn.tedu.utils.JdbcUtil;

import cn.tedu.vo.User;

public class UserDao {

Connection conn=null;

PreparedStatement pstat = null;

ResultSet rs = null;

/**登陆方法

 * @param username:

用户名

 * @param password:

密码

 * @return 用户名和密码对应的用户信息的User类对象,如果不存在返回null

 */

public User login(String username, String password) {

//1、声明用到的对象

User user = null;

//3、获取数据库连接

conn = JdbcUtil.getConn();

try {

//4、预编译sql语句,并返回PreparedStatement对象

pstat = conn.prepareStatement("select * from user where username=?

 and password=?

");

//5、为占位符赋值

pstat.setString(1, username);

pstat.setString(2, password);

//6、执行查询操作,并返回结果集

rs = pstat.executeQuery();

//7、判断结果集中是否有查询结果

if(rs.next()){//有

user = new User();

user.setId(rs.getInt("id"));

user.setUsername(rs.getString("username"));

user.setEmail(rs.getString("email"));

user.setNickname(rs.getString("nickname"));

}

} catch (SQLException e) {

e.printStackTrace();

}finally{

JdbcUtil.close(conn, pstat, rs);

}

//2、返回结果

return user;

}

/**注册用户的方法

 * @param user:

封装了用户信息的User类对象

 * @return 添加成功返回true,失败则返回false

 */

public boolean addUser(User user) {

//1、编写sql语句

String sql = "insert into user(username,password,nickname,email,role) values(?

?

?

?

?

)";

//2、获取数据库连接

conn = JdbcUtil.getConn();

try {

//3、预编译sql语句,并返回pstat

pstat = conn.prepareStatement(sql);

//4、为占位符赋值

pstat.setString(1, user.getUsername());

pstat.setString(2, user.getPassword());

pstat.setString(3, user.getNickname());

pstat.setString(4,user.getEmail());

pstat.setString(5,"user");

//5、执行添加操作,并返回影响的行数

int row = pstat.executeUpdate();

return row>0;

} catch (SQLException e) {

e.printStackTrace();

}finally{

JdbcUtil.close(conn, pstat, rs);

}

return false;

}

/**检查用户名是否存在

 * @param username用户名

 * @return 存在则返回true,反之返回false

 */

public boolean unIsHave(String username){

//1、编写sql语句

String sql = "select * from user where username=?

";

//2获取数据库连接

conn = JdbcUtil.getConn();

try {

//3、预编译sql语句

pstat = conn.prepareStatement(sql);

//4、为占位符赋值

pstat.setString(1, username);

//5、执行查询操作,返回结果集对象

rs = pstat.executeQuery();

//6、返回结果

return rs.next();

} catch (SQLException e) {

e.printStackTrace();

}finally{

JdbcUtil.close(conn, pstat, rs);

}

return false;

}

}

cn.tedu.servlet包

CartAddSerlet.java加入购物车

package cn.tedu.servlet;

import java.io.IOException;

import java.util.HashMap;

import java.util.Map;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import cn.tedu.dao.ProdDao;

import cn.tedu.vo.Product;

public class CartAddServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

//1、接收商品id

String id = request.getParameter("id");

//2、从session中获取cart

Object obj = request.getSession().getAttribute("cart");

Map cart = null;

if(obj==null){//说明session中没有购物车的信息

cart = new HashMap();

//将cart保存到session中

request.getSession().setAttribute("cart", cart);

}else{//说明session中有购物车的信息

cart = (Map)obj;

}

ProdDao prodDao = new ProdDao();

Product prod = prodDao.findProdById(id);

//如果当前商品已经购买过,则在原购买数量的基础上加1

if(cart.containsKey(prod)){

cart.put(prod, cart.get(prod)+1);

}else{//如果当前商品没有购买过,则向cart集合对象添加一个元素,购买数量为1

cart.put(prod, 1);

}

//跳转到cart.jsp

response.sendRedirect(request.getContextPath()+"/cart.jsp");

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

}

}

LoginSerlet.java登录页面

package cn.tedu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import cn.tedu.dao.UserDao;

import cn.tedu.vo.User;

public class LoginServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

//1、接收form表单提交过来的参数

String username = request.getParameter("username");

String password = request.getParameter("password");

//2、验证用户名是否为空

if(username==null||"".equals(username)){

//提示信息

request.setAttribute("msg", "用户名不能为空!

");

//转发到登陆页面

request.getRequestDispatcher("/login.jsp").forward(request, response);

return;

}

//3、验证密码不能为空

if(password==null||"".equals(password)){

//提示信息

request.setAttribute("msg", "密码不能为空");

//转发到登陆页面

request.getRequestDispatcher("/login.jsp").forward(request, response);

return;

}

//4、调用UserDao类的login方法

//4.1声明并实例化UserDao类的对象

UserDao userDao = new UserDao();

//4.2调用login方法

User user = userDao.login(username,password);

//5、判断是否登陆成功

if(user!

=null){//登陆成功

request.getSession().setAttribute("loginUser", user);

request.getRequestDispatcher("/index.jsp").forward(request, response);

}else{//登陆失败

request.setAttribute("msg", "用户名或密码错误");

request.getRequestDispatcher("/login.jsp").forward(request, response);

}

}

}

LoginoutServlet.java注销

package cn.tedu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import cn.tedu.dao.UserDao;

import cn.tedu.vo.User;

public class LoginServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

//1、接收form表单提交过来的参数

String username = request.getParameter("username");

String password = request.getParameter("password");

//2、验证用户名是否为空

if(username==null||"".equals(username)){

//提示信息

request.setAttribute("msg", "用户名不能为空!

");

//转发到登陆页面

request.getRequestDispatcher("/login.jsp").forward(request, response);

return;

}

//3、验证密码不能为空

if(password==null||"".equals(password)){

//提示信息

request.setAttribute("msg", "密码不能为空");

//转发到登陆页面

reque

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2