不知道对不对,你和数据库的连接应该是由ejb容器来管理的吧。

解决方案 »

  1.   

    lookup方法里,直接查找OracleDS就行了:)
      

  2.   

    数据源我能找到啊
    就是执行
      ps=con.prepareStatement("select ID from STUDENT where ID=?");
    时报错
      

  3.   

    不会啊,如果能找到数据源,那怎么能执行select语句出错呢?除非你配置的数据源不是和你的数据库对应的。再说你用Class.forName不是好用吗?所以我觉得你应该检查下在服务器里的数据源配置。
      

  4.   

    这是数据源的配置 :oralce-ds.xml
    <datasources>
      <local-tx-datasource>
        <jndi-name>OracleDS</jndi-name>
        <connection-url>jdbc:oracle:thin:@127.0.0.1:1521:SAMPLE</connection-url>
        <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
        <user-name>system</user-name>
        <password>manager</password> 
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>     
      </local-tx-datasource>
    </datasources>
    不知道joss配置数据源除了配置这一文件还配置哪些??
    CMP时我也就配置这个文件,能用
      

  5.   

    你改成用bean容器来管理你的数据库连接,然后再试试。
    我刚做了一个jboss+mysql的bmp实现,测试成功。
      

  6.   

    to sjcode
      我用的是jboss+eclipse+oracle,你用的是什么?
    代码:
     public String ejbFindByPrimaryKey(String key) throws FinderException {
      Connection con= null;
      PreparedStatement ps = null;
      ResultSet rs = null;
      try {
             con=getConnection();
       ps=con.prepareStatement("select* from DB where SID=?");
       ps.setString(1,key);
       rs=ps.executeQuery();
       System.out.println("successful");

      }catch (Exception e) {
    e.printStackTrace();
      }finally{
       try{
       if(rs!=null){rs.close();}
       if(ps!=null){rs.close();}
       if(con!=null){rs.close();}
       }catch(Exception ignore){
       ignore.printStackTrace();
       }
      }
      return key;
    }
      public Connection getConnection()throws Exception{
       try{
       Context ctx=new InitialContext();
       javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/OracleDS");
       return ds.getConnection();
      }catch(Exception e)
      {
       System.out.println("Coudn't get datasource");
       e.printStackTrace();
       throw e;
      }
    }
    ejb-jar.xml:
    ........
    <entity >
             <description><![CDATA[<!-- begin-user-doc --> You can insert your documentation for '<em><b>BmpbookBean</b></em>'.]]></description>         <ejb-name>Bmpbook</ejb-name>         <home>com.test.BmpbookHome</home>
             <remote>com.test.Bmpbook</remote>
             <local-home>com.test.BmpbookLocalHome</local-home>
             <local>com.test.BmpbookLocal</local>         <ejb-class>com.test.BmpbookBMP</ejb-class>
             <persistence-type>Bean</persistence-type>
             <prim-key-class>java.lang.String</prim-key-class>
             <reentrant>False</reentrant>
     <resource-ref>
     <res-ref-name>OracleDS</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
     </resource-ref>
     
          </entity>
    ........oralce-ds.xml内容如上。
    望能帮帮我,谢谢
      

  7.   

    to sjcode
      如果可以的话,把你测试通过的代码和配置文件发一份给我,好吗?
     非常感谢