一、設計模式簡介
在開發J2EE應用程序時,通常是要找出應用程序中涉及到的各種信息,比如一個公司的產品目錄,或一個網站的用戶信息,我們會將這些信息放在數據庫里。
在通常的設計中,我們要分析這些數據的屬性和關系,然后進行數據庫的邏輯設計,把各種信息用不同的表來存儲。比如,要開發一個圖書信息查詢系統。可以創建下面兩個表來分別表示書和出版社。
table Book (ID, Name, ISBN, Author, PublisherID, PRice, Volume)
table Publisher (ID, Name, Telephone, Address, Postcode)
class Book{ protected intID; protected String Name; protected String ISBN; protected String Author; protected intPublisherID; protected double Price; protected intVolume; public void setID(int iID); public intgetID(); public void setName(String sName); public String getName(); public void setISBN(String sISBN); public String getISBN(); public void setAuthor(String sAuthor); public String getAuthor(); public void setPublisherID(int iID); public intgetPublisherID(); public void setPrice(double dPrice); public double getPrice(); public void setVolume(int iVolume); public intgetVolume(); public Book(int iID, String sName, String sISBN, int ipublisherID, double dPrice, int iVolume); };class BookTable{ void Add(Book book); void Delete(Book book); void Update(Book book); Collection findbyID(int iID); Collection findbyXXXX(XX,XX); Collection findbyPulisherName(String sPublisherName); };con.setAutoCommit(false); PreparedStatement updateSales=con.prepareStatement("UPDATE COFFES SET SALES=? WHERE COF_NAME LIKE ?"); updateSales.setInt(1,50); updateSales.setString(2,"Colombian"); updateSales.executeUpdate(); PreparedStatement updateTotal=con.prepareStatement("UPDATE COFFEES SET TOTAL =TOTAL+ ? WHERE COD_NAME LIKE ?"); updateTotal.setInt(1,50); updateTotal.setString(2,"Colombian"); updateTotal.executeUpdate(); con.commit(0; con.setAutoCommit(true);新聞熱點
疑難解答