你这是自己写的各类吧!
我给你贴一个
package com.sun.j2ee.blueprints.catalog.dao;import javax.naming.NamingException;
import javax.naming.InitialContext;import com.sun.j2ee.blueprints.catalog.util.JNDINames;
import com.sun.j2ee.blueprints.catalog.exceptions.CatalogDAOSysException;public class CatalogDAOFactory {    /**
     * This method instantiates a particular subclass implementing
     * the DAO methods based on the information obtained from the
     * deployment descriptor
     */
    public static CatalogDAO getDAO() throws CatalogDAOSysException {        CatalogDAO catDao = null;
        try {
            InitialContext ic = new InitialContext();
            String className = (String) ic.lookup(JNDINames.CATALOG_DAO_CLASS);
            catDao = (CatalogDAO) Class.forName(className).newInstance();
        } catch (NamingException ne) {
            throw new CatalogDAOSysException("CatalogDAOFactory.getDAO:  NamingException while getting DAO type : \n" + ne.getMessage());
        } catch (Exception se) {
            throw new CatalogDAOSysException("CatalogDAOFactory.getDAO:  Exception while getting DAO type : \n" + se.getMessage());
        }
        return catDao;
    }
}
其中JNDINames.CATALOG_DAO_CLASS="java:comp/env/param/CatalogDAOClass"

解决方案 »

  1.   

    to javagoo(阿枫) :
      
          谢谢,我试试
      

  2.   

    to javagoo(阿枫) :  如果要使用com.sun.j2ee.blueprints.catalog.util.JNDINames;需要在工程中引入JBuilder8的哪个包呢? 能给出路径么?
      

  3.   

    String className = (String) ic.lookup(JNDINames.CATALOG_DAO_CLASS);
                catDao = (CatalogDAO) Class.forName(className).newInstance();在你的程序里就是
    String className = yourDAO;//你自己实现的一个DAO类,这里要保证类在你的classpath里即可..然后再
         catDao = (CatalogDAO) Class.forName(className).newInstance();至于上面的String className = (String) ic.lookup(JNDINames.CATALOG_DAO_CLASS);只是一个为了取得类名字的方法而已.用不着死搬硬套,否则,难道你想下载整个blueprints吗? 没必要!! ------------------------------------------------------
               我们还年轻牛奶会有的奶牛也会有的 
                 可天天在 csdn 混这些会有吗 ??
      

  4.   

    classname就是ClassName的字符串形式,比如:要生成com.sun.sample.CataLogDaoClass,填如这个字符串就可以了。这是Java语言特有的,可以根据类名生成这个类的实例
      

  5.   

    直接看petstore的源代码就可以了啊.
      

  6.   

    to  zez(思恩 为老婆多挣钱 鹤清风) :    那么我自己的DAO类如何实现呢?能给我个例子么?
      

  7.   

    我觉得你还是好好看看pstore,这样对你很有帮助!!你下载下来pstore得源码!
      

  8.   

    to :javagoo(阿枫)    我手边资料奇缺,能不能在这里给我贴几个程序,我看一下
      

  9.   

    package com.sun.j2ee.blueprints.catalog.dao;import java.util.Collection;
    import java.util.Locale;import com.sun.j2ee.blueprints.catalog.exceptions.CatalogDAOSysException;import com.sun.j2ee.blueprints.catalog.model.Page;
    import com.sun.j2ee.blueprints.catalog.model.Category;
    import com.sun.j2ee.blueprints.catalog.model.Product;
    import com.sun.j2ee.blueprints.catalog.model.Item;/**
     * This class is an interface which will be implemented by database specific
     * code.
     * This class encapsulates all the SQL calls made by Catalog EJB.
     * This layer maps the relational data stored in the database to
     * the objects needed by Catalog EJB.
    */
    public interface CatalogDAO {    public Category getCategory(String categoryID, Locale l)
            throws CatalogDAOSysException;    public Page getCategories(int start, int count, Locale l)
            throws CatalogDAOSysException;    public Product getProduct(String productID, Locale l)
            throws CatalogDAOSysException;    public Page getProducts(String categoryID, int start, int count, Locale l)
            throws CatalogDAOSysException;    public Item getItem(String itemID, Locale l)
            throws CatalogDAOSysException;    public Page getItems(String productID, int start, int size, Locale l)
            throws CatalogDAOSysException;    public Page searchItems(String query, int start, int size, Locale l)
            throws CatalogDAOSysException;
    }
      

  10.   

    package com.sun.j2ee.blueprints.catalog.dao;import java.sql.*;
    import java.util.*;
    import javax.naming.*;
    import javax.sql.*;// catalog importsimport com.sun.j2ee.blueprints.catalog.util.JNDINames;
    import com.sun.j2ee.blueprints.catalog.model.Page;
    import com.sun.j2ee.blueprints.catalog.model.Category;
    import com.sun.j2ee.blueprints.catalog.model.Product;
    import com.sun.j2ee.blueprints.catalog.model.Item;
    import com.sun.j2ee.blueprints.catalog.util.DatabaseNames;
    import com.sun.j2ee.blueprints.catalog.exceptions.CatalogDAOSysException;// service locator imports
    import com.sun.j2ee.blueprints.servicelocator.ejb.ServiceLocator;
    import com.sun.j2ee.blueprints.servicelocator.ServiceLocatorException;/**
     * This class implements CatalogDAO for cloudscape DB.
     * This class encapsulates all the SQL calls made by Catalog EJB.
     * This layer maps the relational data stored in the database to
     * the objects needed by Catalog EJB.
    */
    public class CloudscapeCatalogDAO implements CatalogDAO {
      public static String GET_CATEGORY_STATEMENT
      = "select name, descn "
      + " from (category a join category_details b on a.catid=b.catid) "
      + " where locale = ? and a.catid = ?";
      public static String GET_CATEGORIES_STATEMENT
      = "select a.catid, name, descn "
      + " from (category a join category_details b on a.catid=b.catid) "
      + " where locale = ? order by name";
      public static String GET_PRODUCT_STATEMENT
      = "select name, descn "
      + " from (product a join product_details b on a.productid=b.productid) "
      + " where locale = ? and a.productid = ? ";
      public static String GET_PRODUCTS_STATEMENT
      = "select a.productid, name, descn "
      + " from (product a join product_details b on a.productid=b.productid) "
      + " where locale = ? and a.catid = ? order by name";
      public static String GET_ITEM_STATEMENT
      = "select catid, a.productid, name, b.image, b.descn, attr1, "
      + "  attr2, attr3, attr4, attr5, listprice, unitcost "
      + " from (((item a join item_details b on a.itemid=b.itemid)"
      + "   join product_details c on a.productid=c.productid)"
      + "   join product d on d.productid = c.productid and b.locale = c.locale) "
      + " where b.locale = ? and a.itemid = ?";
      public static String GET_ITEMS_STATEMENT
      = "select catid, name, a.itemid, b.image, b.descn, attr1, "
      + "  attr2, attr3, attr4, attr5, listprice, unitcost "
      + " from (((item a join item_details b on a.itemid=b.itemid)"
      + "  join product_details c on a.productid=c.productid)"
      + "  join product d on d.productid=c.productid and b.locale = c.locale)"
      + " where b.locale = ? and a.productid = ?";
      public static String[] SEARCH_ITEMS_STATEMENT_FRAGMENTS
      = { "select catid, a.productid, name, a.itemid, b.image, b.descn, attr1,"
          + "  attr2, attr3, attr4, attr5, listprice, unitcost"
          + " from (((item a join item_details b on a.itemid=b.itemid)"
          + "  join product_details c on a.productid=c.productid)"
          + "  join product d on d.productid=c.productid and b.locale = c.locale)"
          + " where b.locale = ? ",
          "    and ((lower(name) like ? ",
          "          or lower(name) like ? ",
          "    ) or (lower(catid) like ? ",
          "          or lower(catid) like ? ",
          "    ) or (lower(b.descn) like ? ",
          "          or lower(b.descn) like ? ",
          ") )"
      };  // Helper methods  protected static DataSource getDataSource() throws CatalogDAOSysException {
          try {
              ServiceLocator sl = new ServiceLocator();
              return (DataSource) sl.getDataSource(JNDINames.CATALOG_DATASOURCE);
          } catch (ServiceLocatorException slx) {
                    throw new CatalogDAOSysException("NamingException while looking up DB context : " +
                                           slx.getMessage());
          }
      }  // Business methods  public Category getCategory(String categoryID, Locale l)
        throws CatalogDAOSysException {
          Connection c = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          Category ret = null;      try {
            c = getDataSource().getConnection();
            ps = c.prepareStatement(GET_CATEGORY_STATEMENT,
                                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
            ps.setString(1, l.toString());
            ps.setString(2, categoryID);
            rs = ps.executeQuery();
            if (rs.first()) {
              ret = new Category(categoryID, rs.getString(1), rs.getString(2));
            }        rs.close();
            ps.close();
            c.close();
            return ret;
          } catch (SQLException se) {
            throw new CatalogDAOSysException("SQLException: " + se.getMessage());
          }
      }  public Page getCategories(int start, int count, Locale l)
        throws CatalogDAOSysException {
          Connection c = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          Page ret = null;      try {
            c = getDataSource().getConnection();
            ps = c.prepareStatement(GET_CATEGORIES_STATEMENT,
                                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
            ps.setString(1, l.toString());
            rs = ps.executeQuery();
            if (start >= 0 && rs.absolute(start+1)) {
              boolean hasNext = false;
              List items = new ArrayList();
              do {
                items.add(new Category(rs.getString(1).trim(),
                                       rs.getString(2),
                                       rs.getString(3)));
              } while ((hasNext = rs.next()) && (--count > 0));
              ret = new Page(items, start, hasNext);
            } else {
              ret = Page.EMPTY_PAGE;
            }        rs.close();
            ps.close();
            c.close();
            return ret;
          } catch (SQLException se) {
            se.printStackTrace(System.err);
            throw new CatalogDAOSysException("SQLException: " + se.getMessage());
          }
      }
      

  11.   

    public Product getProduct(String productID, Locale l)
        throws CatalogDAOSysException {
          Connection c = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          Product ret = null;      try {
            c = getDataSource().getConnection();
            ps = c.prepareStatement(GET_PRODUCT_STATEMENT,
                                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
            ps.setString(1, l.toString());
            ps.setString(2, productID);
            rs = ps.executeQuery();
            if (rs.first()) {
              ret = new Product(productID, rs.getString(1), rs.getString(2));
            }        rs.close();
            ps.close();
            c.close();
            return ret;
          } catch (SQLException se) {
            throw new CatalogDAOSysException("SQLException: " + se.getMessage());
          }
      }  public Page getProducts(String categoryID, int start, int count, Locale l)
        throws CatalogDAOSysException {
          Connection c = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          Page ret = null;      try {
            c = getDataSource().getConnection();
            ps = c.prepareStatement(GET_PRODUCTS_STATEMENT,
                                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
            ps.setString(1, l.toString());
            ps.setString(2, categoryID);
            rs = ps.executeQuery();
            if (start >= 0 && rs.absolute(start+1)) {
              boolean hasNext = false;
              List items = new ArrayList();
              do {
                items.add(new Product(rs.getString(1).trim(),
                                      rs.getString(2).trim(),
                                      rs.getString(3).trim()));
              } while ((hasNext = rs.next()) && (--count > 0));
              ret = new Page(items, start, hasNext);
            } else {
              ret = Page.EMPTY_PAGE;
            }        rs.close();
            ps.close();
            c.close();
            return ret;
          } catch (SQLException se) {
            throw new CatalogDAOSysException("SQLException: " + se.getMessage());
          }
      }  public Item getItem(String itemID, Locale l)
        throws CatalogDAOSysException {
          Connection c = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          Item ret = null;      try {
            c = getDataSource().getConnection();
            ps = c.prepareStatement(GET_ITEM_STATEMENT,
                                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
            ps.setString(1, l.toString());
            ps.setString(2, itemID);
            rs = ps.executeQuery();
            if (rs.first()) {
              int i = 1;
              ret = new Item(rs.getString(i++).trim(),
                             rs.getString(i++).trim(),
                             rs.getString(i++),
                             itemID,
                             rs.getString(i++).trim(),
                             rs.getString(i++),
                             rs.getString(i++),
                             rs.getString(i++),
                             rs.getString(i++),
                             rs.getString(i++),
                             rs.getString(i++),
                             rs.getDouble(i++),
                             rs.getDouble(i++));
            }        rs.close();
            ps.close();
            c.close();
            return ret;
          } catch (SQLException se) {
            throw new CatalogDAOSysException("SQLException: " + se.getMessage());
          }
      }  public Page getItems(String productID, int start, int count, Locale l)
        throws CatalogDAOSysException {
          Connection c = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          Page ret = null;      try {
            c = getDataSource().getConnection();
            ps = c.prepareStatement(GET_ITEMS_STATEMENT,
                                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
            ps.setString(1, l.toString());
            ps.setString(2, productID);
            rs = ps.executeQuery();
            if (start >= 0 && rs.absolute(start+1)) {
              boolean hasNext = false;
              List items = new ArrayList();
              do {
                int i = 1;
                items.add(new Item(productID,
                                   rs.getString(i++).trim(),
                                   rs.getString(i++),
                                   rs.getString(i++).trim(),
                                   rs.getString(i++).trim(),
                                   rs.getString(i++),
                                   rs.getString(i++),
                                   rs.getString(i++),
                                   rs.getString(i++),
                                   rs.getString(i++),
                                   rs.getString(i++),
                                   rs.getDouble(i++),
                                   rs.getDouble(i++)));
              } while ((hasNext = rs.next()) && (--count > 0));
              ret = new Page(items, start, hasNext);
            } else {
              ret = Page.EMPTY_PAGE;
            }        rs.close();
            ps.close();
            c.close();
            return ret;
          } catch (SQLException se) {
            throw new CatalogDAOSysException("SQLException: " + se.getMessage());
          }
      }
      

  12.   

    to javagoo(阿枫) :
       谢谢