www.pudn.com > StoreJava.rar > BookList.java


package com.bitc.store;  
//定义Bean所属的套件  
  
//定义欲使用的套件  
import java.sql.*;  
  
public class BookList  
{  
	//与资料库连结有关的Bean属性  
	private Connection con = null;  
	private Statement stmt = null;  
	private ResultSet BookRs = null;  
  
	public BookList()  //建构子  
	{		  
	}	  
  
	//以下为设定Bean属性的方法  
	public void InitBookRs(Connection con, String filter)  
	{  
		try{  
			if(this.con != con)  
			{  
				this.con = con;				  
			}			  
  
			stmt = con.createStatement(  
					ResultSet.TYPE_SCROLL_INSENSITIVE,  
					ResultSet.CONCUR_READ_ONLY);  
			//建立Statement物件		  
  
			BookRs = stmt.executeQuery  
				 ("SELECT * FROM Book WHERE " + filter);  
			//执行SQL叙述从Book资料表取得记录  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}		  
	}  
  
	//关闭ResultSet物件  
	public void CloseBookRs ()  
	{   
		try{  
			if(BookRs != null)  
			{  
				BookRs.close();  
				BookRs = null;  
			}  
  
			if(stmt != null)  
			{  
				stmt.close();  
				stmt = null;  
			}  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}  
	}  
  
	//移至下一笔记录  
	public boolean next()  
	{  
		boolean result = false;  
		  
		try{  
			result = BookRs.next();			  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}		  
		return result;  
	}  
  
	//取得记录集中ID栏位的资料	  
	public String getID()  
	{  
		String result = null;  
  
		try{  
			result = BookRs.getString("ID");  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}		  
		return result;  
	}  
	  
	//取得记录集中BookID栏位的资料  
	public String getBookID()  
	{   
		String result = null;  
  
		try{  
			result = BookRs.getString("BookID");  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}		  
		return result;  
	}	  
	  
	//取得记录集中BookNm栏位的资料  
	public String getBookNm()  
	{   
		String result = null;  
		try{  
			result = BookRs.getString("BookNm");  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}		  
		return result;  
	}  
  
	//取得记录集中Author栏位的资料  
	public String getAuthor()  
	{   
		String result = null;  
  
		try{  
			result = BookRs.getString("Author");  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}  
  
		return result;  
	}  
  
	//取得记录集中Price栏位的资料  
	public String getPrice()  
	{   
		String result = null;  
  
		try{  
			result = BookRs.getString("Price");  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}		  
		return result;  
	}  
  
	//取得记录集中Abstract栏位的资料  
	public String getAbstract()  
	{   
		String result = null;  
  
		try{  
			result = BookRs.getString("Abstract");  
		}  
		catch(SQLException sex)  
		{  
			System.out.println(sex.toString());  
		}		  
		return result;  
	}  
}