[jboss-user] [EJB 3.0] - Re: Accessing JBoss Datasource from EJB 3.0
jaikiran
do-not-reply at jboss.com
Mon Aug 25 05:13:48 EDT 2008
"mabimal" wrote :
| I am in need to develop EJB 3.0 such that it accesses the JBoss Datasource and connect to the database and ready to answer the queries from clients.
|
|
When you say EJB3, do you mean, EJB3 entities? Or is it EJB3 Session Beans?
DataSource(s) are bound to the JNDI tree when deployed. So if your datasource contains something like:
| <?xml version="1.0" encoding="UTF-8"?>
|
|
| <datasources>
| <local-tx-datasource>
| <jndi-name>MyAppDS</jndi-name>
|
| <connection-url>...</connection-url>
| <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
| <user-name>xyz</user-name>
| <password>abc</password>
|
| </local-tx-datasource>
|
| </datasources>
Then in your EJB3 bean, you can lookup the datasource as follows:
Context ctx = new InitialContext();
| DataSource ds = (DataSource) ctx.lookup("java:/MyAppDS");
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172236#4172236
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172236
More information about the jboss-user
mailing list