ITPub博客

首页 > 应用开发 > Java > JSP for shopping box

JSP for shopping box

原创 Java 作者:nonamedemo 时间:2007-09-03 23:00:00 0 删除 编辑

============

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/,如需转载,请注明出处,否则将追究法律责任。

上一篇: chat room
下一篇: Timer(C#)
请登录后发表评论 登录
全部评论
  • 博文量
    31
  • 访问量
    11658