WEB开发网
开发学院数据库DB2 DB2 XML 编程,第 1 部分: 理解 XML 数据模型 阅读

DB2 XML 编程,第 1 部分: 理解 XML 数据模型

 2010-10-01 16:25:02 来源:WEB开发网   
核心提示: 清单 2. 创建 Items 类public class Items{Hashtable list=new Hashtable();Public Items(int custid,Connection conn){Statement dbstmt= conn.createStatement();

清单 2. 创建 Items 类

public class Items
{
Hashtable list=new Hashtable();
Public Items(int custid,Connection conn)
{
Statement dbstmt= conn.createStatement();
ResultSet dbResult = dbstmt.executeQuery("select itemid, description,
price, date from purchase_table where customerid=custid")
While (dbResult.rs.next ())
{
tempitem = new Item();
tempitem.SetID(dbResult. getString(1));
tempitem. SetDescription (dbResult. getString(2));
tempitem. Setprice (dbResult. getFloat(3));
tempitem. SetpurchaseDate (dbResult. getString(4));
Additem (tempitem);
}
}
public void AddItem (item oneitem) {list.put(oneitem.GetID(),oneitem);}
public Item GetItem (ItemID) {return list.get(String itemID);}
public Hashtable GetItems(){return list;}
public Items FindItemByPrice (flaot min, float max)
{
Items retList=new Items();
for (Enumeration e=list.elements () ; e.hasMoreElements() ; )
{
item tmpItem=(item)e.nextElement();
float price= tmpItem .GetPrice();
if(price >= min && price <=max)
{
retList.AddItem(tmpItem);
}
}
}
public Items FindItemByDate (purchaseDate) { }
}

清单 3. 创建 Item 定义

public class Item
{
String id;
String description;
String purchaseDate;
Float price;
Public void SetID (String ItemID) {id= ItemID;}
Public void SetDescription (String desc) { description = desc;}
Public void SetpurchaseDate (String pDate) { purchaseDate = pDate ;}
Public void Setprice (float pprice { price = pprice ;}
Public String GetID (){return id;}
Public String GetDescription(){return description;}
Public float GetPrice(){return price;}
}

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:DB XML 编程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接