连接数据库的那段代码贴出来哦!private String dbName = "java:comp/env/jdbc/SavingsAccountDB";   private void makeConnection() throws NamingException, SQLException {      InitialContext ic = new InitialContext();
      DataSource ds = (DataSource) ic.lookup(dbName);
      con =  ds.getConnection();
   }
   public void setEntityContext(EntityContext context) {      this.context = context;
      try {
         makeConnection();
      } catch (Exception ex) {
          throw new EJBException("Unable to connect to database. " +
             ex.getMessage());
      }
   }

解决方案 »

  1.   

    没有问题的,savingsaccount栏可以看到我建的数据表
    结构如下:-DataSource
               |-jdbc/SavingsAccountDB
                 |--savingsaccount
                    |---id
                    |---..
                    |---.....
     
    部署文件如下:<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
        <enterprise-beans>
            <entity>
                <display-name>SavingsAccountBean</display-name>
                <ejb-name>SavingsAccountBean</ejb-name>
                <home>savingsaccount.SavingsAccountHome</home>
                <remote>savingsaccount.SavingsAccount</remote>
                <ejb-class>savingsaccount.SavingsAccountBean</ejb-class>
                <persistence-type>Bean</persistence-type>
                <prim-key-class>java.lang.String</prim-key-class>
                <reentrant>False</reentrant>
                <resource-ref>
                    <description />
                    <res-ref-name>jdbc/SavingsAccountDB</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <res-auth>Container</res-auth>
                </resource-ref>
            </entity>
        </enterprise-beans>
        <assembly-descriptor>
            <container-transaction>
                <method>
                    <ejb-name>SavingsAccountBean</ejb-name>
                    <method-name>*</method-name>
                </method>
                <trans-attribute>Required</trans-attribute>
            </container-transaction>
        </assembly-descriptor>
    </ejb-jar>   
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE jboss PUBLIC '-//JBoss//DTD JBOSS 3.0//EN' 'http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd'>
    <!--
    Generated by JBoss OpenTool 2.5 for JBoss Server 2.4.x** DO NOT MAKE MANUAL MODIFICATIONS TO THIS FILE **
    This deployment descriptor will be regenerated every time changes are made in the EJB designer.Features provided by this opentool:
    - Right-click on EJB node to:
      * (un)deploy jar or ear file
      * list deployments
      * run/debug/optimize JBoss server
    - JBoss DD Editor tab for each EJB node in your project
    - JBoss properties tab for each Enterprise Java Bean
    - When specifying JBoss properties you may use a vertical pipe (|)
      to separate multiple values. Doing so will cause the opentool to
      generate multiple XML nodes in the JBoss deployment descriptor,
      one for each value specified
    - Automatic generation of jboss.xml, jaws.xml and jbosscmp-jdbc.xml based on:
      * Above mentioned property tabs
      * Table and column names specifed for EJB fields in EJB designer
      * Table and column names specifed for EJB relationships in EJB designer
        (You need to setup a data source to use this EJB designer feature)
      * EJB DD Editor 'Authorization Domain' used as JBoss 'security-domain'
        (Can be overridden by 'security-domain' JBoss property)
      * EJB DD Editor 'Destination Name' used as 'destination-jndi-name'
        for Message Driven BeanPeculiarities to be aware of:
    - When switching between durable and non-durable settings for
      message driven beans you will need to close the message driven
      bean designer tab before the list of JBoss related properties
      on the JBoss Properties tab will be updated
    - You must (temporarily) leave the 'JBoss DD Editor' tab in order
      for any changes to take affect-->
    <jboss>
        <enterprise-beans>
            <entity>
                <ejb-name>SavingsAccountBean</ejb-name>
                <jndi-name>SavingsAccountEJB</jndi-name>
                <resource-ref>
                    <res-ref-name>jdbc/SavingsAccountDB</res-ref-name>
                    <jndi-name>java:/jdbc/SavingsAccountDB</jndi-name>
                </resource-ref>
            </entity>
        </enterprise-beans>
    </jboss>我搞了两个星期了,没有搞出来,我几乎认为ejb是骗人的。清高手指教啊!