Discussions

EJB design: Connection to the database through BMP

  1. Connection to the database through BMP (3 messages)

    hai
        i wrote a BMP bean to insert values in to the database.
    the following is the code.

    In setEntityContext Method..
    public void setEntityContext(EntityContext ctx)
    {
     this.ctx=ctx;
    try
    {
      getConnection();
    }catch(){}

    In getConnection Method....
    dbName="java:comp/env/jdbc/oraclePool";
    public Connection getConnection()throws SQLException
    {
      Context c=new InitialContext();
     DataSource ds=(DataSource).lookup(dbName);
     return ds.getConnection();
    }

    but iam getting an error as unable to connect to the database "java:comp/env/jdbc/oraclePool"

    so can u people tell me what is wrong with code

    thanks
    kiranlal

  2. Connection to the database through BMP[ Go to top ]

    Check deployment descriptor for the resource ref tags.
    <resource-ref>
    <res-ref-name>jdbc/oraclePool</res-ref-name>
    <res-type>javax.sql.DataSource<res-type>
    <res-auth>Container</res-auth>
    <res-link>xxx</res-link>
    </resource-ref>

    XXX- refers to connection cache on your Application server.


    Gamini

  3. Connection to the database through BMP[ Go to top ]

    i did not understand the reply because i did not find anything related to<res-link>xxx</res-link>in any book.
    ao please let me know what exactly it is and more ever we can work with BMP without writing any deployment descriptor.
               so please let me know.
    thanks
    kiranlal
  4. Connection to the database through BMP[ Go to top ]

    hi kiran,

    I don't think it's a good idea to get the connection in the "setEntityContext" method. Because of the limit of the number of database connection resource. When the EJB container starts, it'll initiate some pooled Entity Bean Object by calling the setEntityContext method. So, if number of the pooled entity bean instance is larger than the limit of connection of your database, no more connection could be established. I suggest to get the connection as late as possible, for example, get them in the ejbActivate method.

    bikai