There are several ways to get a JDBC connection in EJB3 running on WebSphere:
1. JNDI lookup
2. @Resource Injection
2.1 In ibm-ejb-jar-bnd.xml
<session name="OrderRepositoryBean">
<resource-ref name="DFSAdabasDataSource" binding-name="jdbc/DFS_ADABAS" />
</session>
2.2 In OrderRespositoryBean
@Resource(name = "DFSAdabasDataSource")
private DataSource ds;
3. NOT WORK!!! @Resource Injection by using mappedName, assuming the JNDI name is : jdbc/DFS_ADABAS
// In OrderRepositoryBean
@Resource(mappedName = "jdbc/DFS_ADABAS")
private DataSource ds;
4. Using OpenJPAEntityManager
@PersistenceContext(unitName = "CACSAMP")
private EntityManager emDFS;
......
(Connection) ((OpenJPAEntityManager) emDFS.getDelegate()).getConnection();
Showing posts with label ejb. Show all posts
Showing posts with label ejb. Show all posts
Thursday, December 08, 2011
Friday, November 18, 2011
How to get the Database connection URL from OpenJPA EJB
Normally you would like to have a quick and easy way to tell which DB your application is connect to. To get this kind of you information in an OpenJPA/EJB3 stack, you may be able to do the following:
public String getDataBaseURL() {
final Connection conn = (Connection) ((OpenJPAEntityManager) em.getDelegate()).getConnection();
String url;
try {
url = conn.getMetaData().getURL();
} catch (final SQLException e) {
url = "Failed to get the DB URL";
}
return url;
}
public String getDataBaseURL() {
final Connection conn = (Connection) ((OpenJPAEntityManager) em.getDelegate()).getConnection();
String url;
try {
url = conn.getMetaData().getURL();
} catch (final SQLException e) {
url = "Failed to get the DB URL";
}
return url;
}
Subscribe to:
Posts (Atom)
Full Guide for using Bitnami Prometheus Operator Helm Chart with Additional Scrape Configuration
"The Prometheus Operator for Kubernetes provides easy monitoring definitions for Kubernetes services and deployment and management of...
-
After some digging, finally I got android market working on Android emulator 2.2 running on Windows Vista. Here is the steps,: Start SDK Set...
-
Thingsboard is a fantastic open source IoT data gathering and visualization platform. I was trying to setup the local development mode for ...
-
"The Prometheus Operator for Kubernetes provides easy monitoring definitions for Kubernetes services and deployment and management of...