JSP for shopping box
============
T-SQL
============
if exists ( select * from sysdatabases where name = 'shop')
drop database shop
go
create database shop
use shop
go
if exists(select * from sysobjects where name ='product')
drop table product
go
create table product
(
prodId varchar(15) not null primary key,
prodName varchar(20) not null ,
prodPrice money not null,
prodNumber int
)
go
select * from product
insert into product values('XSQ001','sumsang顯示器',2000,null)
insert into product values('XSQ002','sharp顯示器',4000,null)
insert into product values('XSQ003','BenQ顯示器',1000,null)
insert into product values('XSQ004','Acer顯示器',3000,null)
insert into product values('XSQ005','AOC顯示器',2200,null)
insert into product values('XSQ006','ViewSonic顯示器',1500,null)
=========================
shopping car
==========================
package shoppingcar;
import java.sql.*;
import java.util.ArrayList;
import java.util.Hashtable;
public class shoppingcar {
private Hashtable productlist;
public shoppingcar() {
productlist = this.getProductlist();
}
public Hashtable getProductlist() {
return productlist;
}
//新增一個商品
public void addproduct(String prodId, product prod) {
productlist.put(prodId, prod);
}
//獲取一個商品
public product getproduct(String prodId) {
return (product) productlist.get(prodId);
// product prod = null;
// Connection con = null;
// con = DBManager.getConnection();
// String sql = "select * from product where prodId='" + prodId + "'";
// try {
// Statement stmt = con.createStatement();
// ResultSet rs = stmt.executeQuery(sql);
// prod.setProdId(rs.getString("prodId"));
// prod.setProdName(rs.getString("prodName"));
// prod.setProdPrice(rs.getFloat("prodPrice"));
// prod.setProdNumber(rs.getInt("prodNumber"));
// } catch (SQLException ex) {
// ex.printStackTrace();
// } finally {
// try {
// con.close();
// } catch (SQLException ex1) {
// ex1.printStackTrace();
// }
// }
//
// return prod;
}
//刪除一個商品
public void removeprod(String prodId) {
productlist.remove(prodId);
}
}
=================
product
==================
package shoppingcar;
public class product {
private String prodId;
private String prodName;
private int prodNumber;
private float prodPrice;
public product() {
}
public void setProdId(String prodId) {
this.prodId = prodId;
}
public void setProdName(String prodName) {
this.prodName = prodName;
}
public void setProdNumber(int prodNumber) {
this.prodNumber = prodNumber;
}
public void setProdPrice(float prodPrice) {
this.prodPrice = prodPrice;
}
public String getProdId() {
return prodId;
}
public String getProdName() {
return prodName;
}
public int getProdNumber() {
return prodNumber;
}
public float getProdPrice() {
return prodPrice;
}
}
==================
DBManager
===================
package shoppingcar;
import java.sql.*;
public class DBManager {
public DBManager() {
}
public static Connection getConnection() {
Connection con = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
try {
DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;dataBaseName=shop",
"sa", "");
} catch (SQLException ex1) {
ex1.printStackTrace();
}
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return con;
}
}
============
continuing.........................................
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10395457/viewspace-967786/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Ex-shopping car
- Online Shopping App RequirementsAPPUIREM
- Patrick and Shopping Codeforces Round #332
- jsp頁面中點選(checkbox)或者radio隱藏trJS
- HDU3264 Open-air shopping malls (圓交+二分)AI
- jsp include directive, jsp:include action, jsp:plugin action compareJSPlugin
- jsp標籤jsp:useBean用法JSBean
- jsp基礎-初識jspJS
- JSPJS
- Qt之QSpinBox,QDoubleSpinBox及自定義QSpinBoxQT
- Servlets & JSPServletJS
- JSP 教程JS
- JSP動畫JS動畫
- jsp中JS
- JSP原理JS
- Qt之QSpinBox和QDoubleSpinBoxQT
- Flutter 佈局(五)- LimitedBox、Offstage、OverflowBox、SizedBox詳解FlutterMITZed
- EasyUI - Datebox和Numberbox的使用UI
- SUN-VirutalBox vboxheadless命令
- WPF ListBox ListBox.ItemTemplate DataTemplate
- 報錯資訊 The jsp:param action must not be used outside the jsp:include, jsp:forward, or jsp:params elements 的原因及解決辦法JSIDEForward
- JSP系列四:JSP9個內建物件JS物件
- JSP開發入門(三)----JSP與JavaBean (轉)JSJavaBean
- Swipebox
- ITToolBox
- JSP 結構JS
- jsp forward 指令JSForward
- JavaWeb之JSPJavaWebJS
- JSP入門JS
- index.jspIndexJS
- jsp福利喲JS
- Embeded Jetty with JSPJettyJS
- JSP筆記JS筆記
- JSP行為JS
- JSP面試題JS面試題
- JSP基礎JS
- jsp servlet javabeanJSServletJavaBean
- jsp:useBean用法JSBean