ImageVerifierCode 换一换
你正在下载:

Java EE.docx

[预览]
格式:DOCX , 页数:21 ,大小:19.33KB ,
资源ID:7257068      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7257068.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java EE.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java EE.docx

1、Java EE1、package dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class BaseDao private static final String DRIVER=sun.jdbc.odbc.JdbcOdbcDriver; private static final String URL=jdbc:odbc:goods; privat

2、e Connection conn = null; public Connection getConn() try Class.forName(DRIVER); catch (ClassNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); try conn = DriverManager.getConnection(URL); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); return c

3、onn; public void closeAll(ResultSet rs,Statement stmt,Connection conn) if(rs != null) try rs.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); if(stmt != null) try stmt.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); if(conn

4、 != null) try conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); public int update(String sql,String params) int row = 0; conn = this.getConn(); try pstmt = conn.prepareStatement(sql); for(int i =0;iparams.length;i+) pstmt.setString(i+1, paramsi); row = pstmt

5、.executeUpdate(sql); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); finally this.closeAll(null, pstmt, conn); return row; public static void main(String args) BaseDao bd = new BaseDao(); System.out.println(bd.getConn(); 2、package dao;import java.util.List;import entity

6、.Goods;public interface GoodsDao public List findList();/获得商品列表 public int getPageCount(int pagesize);/根据一页显示的记录数,获取结果集中能分的总页数 public Goods getGoods(int id);/根据商品Id获得商品信息 public int delGoods(int id);/根据商品Id删除商品 public int addGoods(Goods goods);/添加商品信息 public int updateGoods(Goods goods);/更新商品信息3、pac

7、kage dao.impl;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.List;import dao.BaseDao;import dao.GoodsDao;import entity.Goods;public class GoodsDaoImpl extends Ba

8、seDao implements GoodsDao public int delGoods(int id) int row = 0 ; String sql = delete from goods where id = ?; Connection conn = null; PreparedStatement pstmt = null; try conn = super.getConn(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); row = pstmt.executeUpdate(); catch (SQLExcepti

9、on e) / TODO Auto-generated catch block e.printStackTrace(); finally super.closeAll(null, pstmt, conn); return row; public List findList() List listGoods = new ArrayList(); String sql = select * from goods order by name asc; Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null

10、; try conn = super.getConn(); pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); while(rs.next() Goods goods = new Goods(); goods.setId(rs.getInt(id); goods.setName(rs.getString(name); goods.setProvider(rs.getString(provider); goods.setPrice(rs.getString(price); goods.setQuantity(rs.getI

11、nt(quantity); listGoods.add(goods); rs.last(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); finally super.closeAll(rs, pstmt, conn); return listGoods; public Goods getGoods(int id) /根据商品Id获得商品信息 String sql = select * from goods where id = ?; Connection conn = null; P

12、reparedStatement pstmt = null; ResultSet rs = null; Goods goods = null; try conn = super.getConn(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); rs = pstmt.executeQuery(); if(rs.next() goods = new Goods(); goods.setId(id); goods.setName(rs.getString(name); goods.setProvider(rs.getString(

13、provider); goods.setPrice(rs.getString(price); goods.setQuantity(rs.getInt(quantity); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); finally super.closeAll(rs, pstmt, conn); return goods; public int addGoods(Goods goods) /添加商品信息 int row = 0; String sql = insert into go

14、ods (name,provider,price,quantity) values(?,?,?,?); Connection conn = null; PreparedStatement pstmt = null; try conn = super.getConn(); pstmt = conn.prepareStatement(sql); pstmt.setString(1, goods.getName(); pstmt.setString(2, goods.getProvider(); pstmt.setString(3, goods.getPrice(); pstmt.setInt(4,

15、 goods.getQuantity(); row = pstmt.executeUpdate(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); finally super.closeAll(null, pstmt, conn); return row; public int updateGoods(Goods goods) int row = 0; String sql = update goods set name=?,provider=?,price=?,quantity=?

16、where id=?; Connection conn = null; PreparedStatement pstmt = null; try conn = super.getConn(); pstmt = conn.prepareStatement(sql); pstmt.setString(1, goods.getName(); pstmt.setString(2, goods.getProvider(); pstmt.setString(3, goods.getPrice(); pstmt.setInt(4, goods.getQuantity(); pstmt.setInt(5, go

17、ods.getId(); row = pstmt.executeUpdate(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); finally super.closeAll(null, pstmt, conn); return row; public static void main(String args) GoodsDao goodsDao = new GoodsDaoImpl();int row = goodsDao.updateGoods(11,aa,ff,1222,121)

18、; if(row0) System.out.println(gengxin成功!); 4、package servelet;import java.io.IOException;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.h

19、ttp.HttpSession;import dao.GoodsDao;import dao.impl.GoodsDaoImpl;import entity.Goods;public class GoodsList extends HttpServlet public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException this.doPost(req, resp);/ super.doGet(req, resp); public void doPost

20、(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException GoodsDao goodsDao = new GoodsDaoImpl(); List list = goodsDao.findList(); HttpSession session = req.getSession(); session.setAttribute(Goodslist, list); resp.sendRedirect(/goods/listServlet.jsp);/ super.doPost(req

21、, resp); 5、listServlet.jsp %taglib prefix=c uri=商品信息列表 商品信息列表 编号 商品名 供货商 售出价格(元) 商品数量(台) 操作 $i& $goods.id&$status.index+1 $goods.name $goods.provider $goods.price $goods.quantity 删除 更新 添加商品 6、package servelet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.

22、http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import dao.GoodsDao;import dao.impl.GoodsDaoImpl;public class Dodelete extends HttpServlet public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOExcept

23、ion int id = Integer.parseInt(req.getParameter(id); GoodsDao goodsDao = new GoodsDaoImpl(); int row = goodsDao.delGoods(id); if(row0) resp.sendRedirect(results.html); / System.out.println(id);/ super.doGet(req, resp); Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException / TODO Auto-generated method stub/ super.doPost(req, resp); 7、results.html操作成功操作成功!返回8、更新package servelet;import java.io.IOExc

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1