DataSource in a stateless session bean
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mike_jarito
Posted On:   Wednesday, December 11, 2002 07:59 PM

can i use a javax.sql.DataSource in a stateless session bean?
where do i put things? and how should i deploy?

thanks

Re: DataSource in a stateless session bean

Posted By:   neal_ravindran  
Posted On:   Thursday, December 12, 2002 08:22 AM

I use Datasource access stuff in my Data Access Object(DAO) class.


private void getDBConnection() throws MenuDAOSysException

{

try{

DataSource ds=(DataSource) context.lookup("jdbc/SQLServerDS");

}

catch{ }


}

Below that I have closeDBConnection and closeDBStatement.


And then I call the DB accessing function in same class.
The class implements an interface..XXXDAO.java(where XXX is some name)and this class is for SQLServer(and so I called this as XXXDAOSQLServer.java)



In the implementation class of EJB, in the function that is supposed to access DB data, I have


XXXDAO dao=getDAO();

someObj=dao.getXXXX();//Note:-this getXXXX function's actual implemetation is in the DAO class.

getDAO() is also defined in the EJB implementation class


The implementation of getDAO is such:-


dao=(XXXDAO) Class.forName((String)context.lookup("java:comp/env/param/XXXDAOClass")).newInstance();

return dao;


In ejb-jar.xml I have 'param/XXXDAOClass' mapped as an env-entry the value of which is XXXDAOSQLServer



Hope all that info helps. Also refer to DAO design pattern.

Re: DataSource in a stateless session bean

Posted By:   Bozidar_Dangubic  
Posted On:   Thursday, December 12, 2002 07:55 AM

You will need to consult your application server for the details but overall you need to do the following

  • in application server's configuration file specify the name of the data source and driver that you will be using. where this file is located and how it is named is specific to the application server
  • place the JDBC driver jar in the app server's classpath (usually 'include' or 'lib' directory or main app server directory)
  • in ejb-jar.xml for the stateless session bean define resource-ref that points to the data source that you specified in the app server's config file

that should do it.
About | Sitemap | Contact