What is more appropriate?
1) Caching database connection as a member variable in Stateless beans or
2) Getting a connection on a need basis and then releasing it?
Cache the DataSource Looked up from JNDI in the Stateless Session Bean and create connection on need basis and release ASAP.
This depends on your application requirement. Suppose your application has transaction then you should get the new connection for each request. If your application has no transaction then you can go with the first case. Also that your application should be used more frequently. Otherwise caching of connection is not good as per performance. Here the main thing is your connection should be used at very frequent intervals of time. Otherwise one connection will be struck at your stateless session bean.
Is you are using (1) then you will end up with transaction and connection starvation issues.