📄 databasebean.java
字号:
/* * DataBaseBean.java * * Created on 2006年5月17日, 上午10:40 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package DAO;import Bean.CartBean;import Common.DbUtil;import VO.CartProduct;import VO.ProductBean;import java.sql.Connection;import java.sql.DriverManager;import java.sql.*;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;/** * * @author boyingking */public class DataBaseBean { private Connection con = null; public Statement stmt = null; private void connectTODB() { try { con = DbUtil.getConnection(); } catch (Exception e) { e.printStackTrace(); } } /** Creates a new instance of DataBaseBean */ public DataBaseBean() { } public Vector selectProduct(String sql) { Statement stmt = null; ResultSet rest = null; Vector vec = new Vector(); this.connectTODB(); try { stmt = this.con.createStatement(); rest = stmt.executeQuery(sql); while (rest.next()) { ProductBean temppro = new ProductBean(); temppro.setProductId(rest.getInt("product_id")); temppro.setProductName(rest.getString("product_name")); temppro.setProductPrice(rest.getDouble("product_price")); temppro.setProductNum(rest.getInt("product_num")); temppro.setProductDescribe(rest.getString("product_describe")); vec.add(temppro); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (rest != null) { rest.close(); } if (stmt != null) { stmt.close(); } if (this.con != null) { con.close(); } } catch (Exception ee) { ee.printStackTrace(); } } return vec; } public void checkOut(CartBean cartbean) { Statement stmt = null; Hashtable hash = cartbean.getCartContent(); Enumeration cartEnu = hash.elements(); this.connectTODB(); while (cartEnu.hasMoreElements()) { CartProduct cartpro = (CartProduct) cartEnu.nextElement(); int id = cartpro.getProductId(); int num = cartpro.getSelectedCount(); try { stmt = con.createStatement(); stmt.executeUpdate("update product set product_num=product_num-" + num + " where product_id=" + id + " and product_num>" + num); } catch (SQLException ex) { ex.printStackTrace(); } } try { if (stmt != null) { stmt.close(); } if (this.con != null) { con.close(); } } catch (Exception ee) { ee.printStackTrace(); } } public void closeDB() { try { if (stmt != null) { stmt.close(); } con.close(); } catch (Exception SqlE) { SqlE.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -