[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Having problem to use JNDI datasource.

sdsani do-not-reply at jboss.com
Sun Feb 22 20:20:12 EST 2009


Hi,

I am new to Jboss and at this point learning about Jboss and JSF. Currently I am working on a very small JSF application (JSF, Spring) that connects to a database (H2) and then reads and display some information from that database. Everything works fine when I perform JNDI lookup from my code as mentioned below.

  | private Connection getConnectionUsingJNDI() throws Exception
  | {
  | 	Properties properties = new Properties();
  | 	properties.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  | 	properties.setProperty(InitialContext.PROVIDER_URL, "jnp://localhost:1099");
  | 		InitialContext ic = new InitialContext(properties);
  | 		
  | 		Connection con = null;
  | 		if (ic != null) {
  | 			DataSource ds = (DataSource) ic.lookup("java:/H2DS");
  | 			con = ds.getConnection();
  | 		}
  | 		return con;
  | }
  | 
Next I tried to configure my JNDI lookup in Spring. Following are the steps that I took.

Added following entry in my spring context file:

  | <jee:jndi-lookup id="dSource" jndi-name="java:/H2DS" resource-ref="true"/>
  | 

Modified my applicationContext.xml file to use new datasource.

  | <bean id="employDAO" class="dao.EmployDAO">
  |     <property name = "dataSource">
  |             <ref bean="dSource"/>
  |     </property>
  | </bean>
  | 

When I deploy my application, I am getting a success, however when I hit this application I am getting a null for DS. Please advice.

Sani


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4212107#4212107

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4212107



More information about the jboss-user mailing list