aspose file tools*
The moose likes JBoss/WildFly and the fly likes NameNotFoundException in database connectivity with Jboss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "NameNotFoundException in database connectivity with Jboss" Watch "NameNotFoundException in database connectivity with Jboss" New topic
Author

NameNotFoundException in database connectivity with Jboss

paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
I am working in JBoss 4.0.3 and oracle 9i. For connection to database i have cp-ds.xml file placed in JBOSS-HOME\server\default\deploy folder.

My cp-ds.xml is like this:

<datasources>
<local-tx-datasource>
<jndi-name>CPDS</jndi-name>
<connection-url>jdbc racle:thin:@3.103.110.19:1521 RCD</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>dapp</user-name>
<password>dapp</password>
<min-pool-size>0</min-pool-size>
<max-pool-size>50</max-pool-size>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>


</datasources>


and i call up in java as:

objDS = (DataSource)initCtxt.lookup("java:CPDS");

but it gives the following error.



19:52:08,884 INFO [STDOUT] javax.naming.NameNotFoundException: CPDS not bound
19:52:08,884 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(Naming
Server.java:514)
19:52:08,884 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(Naming
Server.java:522)
19:52:08,884 INFO [STDOUT] at org.jnp.server.NamingServer.getObject(NamingS
erver.java:528)
19:52:08,884 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServ
er.java:281)
19:52:08,884 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(Namin
gContext.java:610)
19:52:08,884 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(Namin
gContext.java:572)
19:52:08,884 INFO [STDOUT] at javax.naming.InitialContext.lookup(InitialCon
text.java:347)
19:52:08,884 INFO [STDOUT] at com.ge.comfin.cp.common.dao.OracleDAOFactory.
createConnection(Unknown Source)
19:52:08,884 INFO [STDOUT] at com.ge.comfin.cp.common.dao.DropdownValuesDAO
.getCountry(DropdownValuesDAO.java:209)
19:52:08,884 INFO [STDOUT] at com.ge.comfin.cp.impl.UserSetupImpl.populateD
ropDowns(UserSetupImpl.java:438)
19:52:08,884 INFO [STDOUT] at com.ge.comfin.cp.action.UserSetupAction.reque
stAddSetUP(UserSetupAction.java:58)
19:52:08,884 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
19:52:08,884 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
19:52:08,884 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
19:52:08,884 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:3
24)
19:52:08,884 INFO [STDOUT] at org.apache.struts.actions.DispatchAction.disp
atchMethod(DispatchAction.java:274)
19:52:08,884 INFO [STDOUT] at org.apache.struts.actions.DispatchAction.exec
ute(DispatchAction.java:194)
19:52:08,884 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.pro
cessActionPerform(RequestProcessor.java:419)
19:52:08,884 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.pro
cess(RequestProcessor.java:224)
19:52:08,884 INFO [STDOUT] at org.apache.struts.action.ActionServlet.proces
s(ActionServlet.java:1194)
19:52:08,884 INFO [STDOUT] at org.apache.struts.action.ActionServlet.doPost
(ActionServlet.java:432)
19:52:08,884 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:717)
19:52:08,884 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:810)
19:52:08,884 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:252)
19:52:08,884 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:173)
19:52:08,884 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilte




**********************************************************
Are any other setting required.
Can anyone please help out.


Thanks.<br />Paresh Doshi<br />SCJP 1.4
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9327
    
110

Originally posted by paresh doshi:

and i call up in java as:



Is this a standalone java client from which you are doing a lookup? If yes, then you cant access the java: namespace from the standalone client. Have a look at HowCanIAccessADataSourceFromAClient.

Though the solution mentioned there will work, its not a recommended one as mentioned at ConfigDataSources. Here's an extract:

Note: JBoss does not recommend using this feature on a production environment. It requires accessing a connection pool remotely and this is an anti-pattern as connections are not serializable. Besides, transaction propagation is not supported and it could lead to connection leaks if the remote clients are unreliable (i.e crashes, network failure). If you do need to access a datasource remotely, JBoss recommends accessing it via a remote session bean facade.


[My Blog] [JavaRanch Journal]
paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
Hi Jaikiran,

thanks for the reply.

I have inserted

<use-java-context>false</use-java-context>

but still it gives the same error as follows:

21:22:33,409 INFO [STDOUT] javax.naming.NameNotFoundException: CPDS
21:22:33,409 INFO [STDOUT] at org.jboss.ha.jndi.TreeHead.lookup(TreeHead.ja
va:242)
21:22:33,409 INFO [STDOUT] at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:1
55)
21:22:33,409 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
21:22:33,409 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
21:22:33,409 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
21:22:33,409 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:3
24)
21:22:33,409 INFO [STDOUT] at org.jboss.ha.framework.server.HARMIServerImpl
.invoke(HARMIServerImpl.java:209)
21:22:33,409 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
21:22:33,409 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
21:22:33,409 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
21:22:33,409 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:3
24)
21:22:33,409 INFO [STDOUT] at sun.rmi.server.UnicastServerRef.dispatch(Unic
astServerRef.java:261)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.Transport$1.run(Transport.j
ava:148)
21:22:33,409 INFO [STDOUT] at java.security.AccessController.doPrivileged(N
ative Method)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.Transport.serviceCall(Trans
port.java:144)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.tcp.TCPTransport.handleMess
ages(TCPTransport.java:460)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.tcp.TCPTransport$Connection
Handler.run(TCPTransport.java:701)
21:22:33,409 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.StreamRemoteCall.exceptionR
eceivedFromServer(StreamRemoteCall.java:247)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.StreamRemoteCall.executeCal
l(StreamRemoteCall.java:223)


Please let me know if there is any other solution.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9327
    
110

You will have to change the lookup code to:



Did you do that?
paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
Hi Jaikiran,

I am using the same CPDS in lookup. but still it doesnt work. It gives same error.

is it necessary to catch Naming Exception ?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9327
    
110

Originally posted by paresh doshi:
21:22:33,409 INFO [STDOUT] javax.naming.NameNotFoundException: CPDS
21:22:33,409 INFO [STDOUT] at org.jboss.ha.jndi.TreeHead.lookup(TreeHead.ja
va:242)
21:22:33,409 INFO [STDOUT] at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:1
55)

21:22:33,409 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
21:22:33,409 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
21:22:33,409 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
21:22:33,409 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:3
24)
21:22:33,409 INFO [STDOUT] at org.jboss.ha.framework.server.HARMIServerImpl
.invoke(HARMIServerImpl.java:209)
21:22:33,409 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
21:22:33,409 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
21:22:33,409 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
21:22:33,409 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:3
24)
21:22:33,409 INFO [STDOUT] at sun.rmi.server.UnicastServerRef.dispatch(Unic
astServerRef.java:261)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.Transport$1.run(Transport.j
ava:148)
21:22:33,409 INFO [STDOUT] at java.security.AccessController.doPrivileged(N
ative Method)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.Transport.serviceCall(Trans
port.java:144)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.tcp.TCPTransport.handleMess
ages(TCPTransport.java:460)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.tcp.TCPTransport$Connection
Handler.run(TCPTransport.java:701)
21:22:33,409 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.StreamRemoteCall.exceptionR
eceivedFromServer(StreamRemoteCall.java:247)
21:22:33,409 INFO [STDOUT] at sun.rmi.transport.StreamRemoteCall.executeCal
l(StreamRemoteCall.java:223)


Please let me know if there is any other solution.


Did you change something else? This exception stacktrace looks different. Looks like the HAJNDI is being used which will come into picture when you are using the clustering in JBoss. You are deploying your application in %JBOSS_HOME%/server/default/deploy isn't it?

Also, post the code where you are doing the lookup and the entire updated -ds.xml file.

You can also do the following:

- Go to http://localhost:8080/jmx-console
- Click on the service=JNDIView link
- On the page that comes up click on the Invoke button beside the list() method
- A page will come up showing the JNDI contents

Post the content here.
paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
Hi Jaikiran,

I have catched the Naming exception in the code where i do the lookup, i get the following error.

*************Error*****************

10:36:58,356 INFO [STDOUT] Naming ExceptionReceive timed out
10:36:58,376 INFO [STDOUT] 10:36:58,376 ERROR [CPLogger] SSO Id :: [] - Class N
ame [UserSetupImpl] - Method Name (populateDropDowns) - Message { CPException :
null }
10:36:58,376 INFO [STDOUT] 10:36:58,376 ERROR [CPLogger] SSO Id :: [] - Class N
ame [UserSetupImpl] - Method Name (populateDropDowns) - Message { CPException :
null }
10:36:58,386 INFO [STDOUT] 10:36:58,386 ERROR [CPLogger] SSO Id :: [] - Class N
ame [class com.ge.comfin.cp.common.dao.DropdownValuesDAO] - Method Name (getAggr
egationPeriod()) - Message { Exception : null }
10:36:58,386 INFO [STDOUT] inside exception
10:36:58,386 INFO [STDOUT] inside finally
10:36:58,757 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Define tag cannot set a null value
at org.apache.struts.taglib.bean.DefineTag.doEndTag(DefineTag.java:236)
at org.apache.jsp.view.jsp.UserSetup_jsp._jspService(org.apache.jsp.view
.jsp.UserSetup_jsp:363)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
14)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
atcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(Applica
tionDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationD
ispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDis
patcher.java:301)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.
java:1063)
at org.apache.struts.action.RequestProcessor.processForwardConfig(Reques
tProcessor.java:386)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:229)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:119
4)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


**************************************
cp-ds.xml

<datasources>
<local-tx-datasource>
<jndi-name>cp-ds</jndi-name>
<use-java-context>false</use-java-context>
<connection-url>jdbc racle:thin:@3.103.110.19:1521 RCD</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>dapp</user-name>
<password>dapp</password>
<min-pool-size>0</min-pool-size>
<max-pool-size>50</max-pool-size>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>


</datasources>

***********Lookup cod********

public static Connection createConnection() throws CPException,Exception
{
Context initCtxt = null;
DataSource objDS = null;
Connection objConn = null;
String strDataSource = null;
try
{
initCtxt = new InitialContext();
System.out.println("initial context ");
objDS = (DataSource)initCtxt.lookup("cp-ds");
System.out.println("lookup ");

}
catch(NamingException ne)
{
System.out.println("Naming Exception"+ ne.getMessage());
}finally{
try{
if(initCtxt != null)initCtxt.close();
}catch(NamingException ne){
System.out.println("Error Closing COntext: "+ ne);
}
}
objConn = objDS.getConnection();







return objConn;
}


Please suggest your views....
paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
JMX Console->list invoke output
___________________________________

java: Namespace
+- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
+- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
+- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
+- comp (class: javax.naming.Context)
+- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
+- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+- jaas (class: javax.naming.Context)
| +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
| +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
| +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
+- timedCacheFactory (class: javax.naming.Context)
Failed to lookup: timedCacheFactory, errmsg=null
+- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
+- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
+- Mail (class: javax.mail.Session)
+- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
+- TransactionManager (class: org.jboss.tm.TxManager)

Global JNDI Namespace
+- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
+- jmx (class: org.jnp.interfaces.NamingContext)
| +- invoker (class: org.jnp.interfaces.NamingContext)
| | +- RMIAdaptor (proxy: $Proxy39 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
| +- rmi (class: org.jnp.interfaces.NamingContext)
| | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
+- cp-ds (class: javax.sql.DataSource)
+- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+- UserTransactionSessionFactory (proxy: $Proxy12 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
+- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
+- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
+- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
+- queue (class: org.jnp.interfaces.NamingContext)
| +- A (class: org.jboss.mq.SpyQueue)
| +- testQueue (class: org.jboss.mq.SpyQueue)
| +- ex (class: org.jboss.mq.SpyQueue)
| +- DLQ (class: org.jboss.mq.SpyQueue)
| +- D (class: org.jboss.mq.SpyQueue)
| +- C (class: org.jboss.mq.SpyQueue)
| +- B (class: org.jboss.mq.SpyQueue)
+- topic (class: org.jnp.interfaces.NamingContext)
| +- testDurableTopic (class: org.jboss.mq.SpyTopic)
| +- testTopic (class: org.jboss.mq.SpyTopic)
| +- securedTopic (class: org.jboss.mq.SpyTopic)
+- console (class: org.jnp.interfaces.NamingContext)
| +- PluginManager (proxy: $Proxy40 implements interface org.jboss.console.manager.PluginManagerMBean)
+- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
+- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
+- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
+- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
+- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
I tried the same code with JBOSS 4.0, it works fine...

But my project setup is in JBOSS 4.0.3... It gives error for

15:06:33,324 INFO [STDOUT] javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9327
    
110

I tried the same code with JBOSS 4.0, it works fine...


So on your 4.0.3 setup, have done any changes after you downloaded it from the jboss site? I would expect it to run on 4.0.3 as well.
paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
No I did not do any changes in JBoss4.0.3 after download.

Just copied cp-ds.xml in deploy dir and deployed my war file in deploy dir.

I dont know why this error comes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NameNotFoundException in database connectivity with Jboss
 
Similar Threads
connection pool with jboss
JNDI Mapping for oracle datasource
Unable to obtain datasource
Oracle Datasource for jboss
Jboss, connection problem