[jboss-user] [JCA/JBoss] - Can't connect to global namespace datasource from servlet

LostJBossIdeUser do-not-reply at jboss.com
Fri Jul 28 17:14:38 EDT 2006


I just recently started playing with JBoss. I have been successful so far. But now I am stuck on a datasource issue. I need to access a MySQL DB from a servlet to read/write xml content. 

Here is what I have so far: 

mysql-ds.xml - 

<local-tx-datasource> 
<jndi-name>jdbc/MySqlDS</jndi-name> 
<use-java-context>false</use-java-context> 
<connection-url>jdbc:mysql://localhost:3306/proxyServletDB</connection-url> 
<driver-class>com.mysql.jdbc.Driver</driver-class> 
<user-name>root</user-name> 
pword 
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name> 

<type-mapping>mySQL</type-mapping> 

</local-tx-datasource> 


web.xml - 
<web-app> 

<!-- JDBC DataSources (java:comp/env/jdbc) --> 
<resource-ref> 
The default DS 
<res-ref-name>jdbc/MySqlDS</res-ref-name> 
<res-type>javax.sql.DataSource</res-type> 
<res-auth>Container</res-auth> 
</resource-ref> 

< ... > 
</web-app> 

jboss-web.xml - 
<jboss-web> 
<resource-ref> 
<res-ref-name>jdbc/MySqlDS</res-ref-name> 
<res-type>javax.sql.DataSource</res-type> 
<jndi-name>java:/MySqlDS</jndi-name> 
</resource-ref> 
</jboss-web> 

Servlet - 
Context ctx = new InitialContext(); 
DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/MySqlDS"); 

I think these are the relevant files. I could access the datasource from the local jndi namespace by using lookup("java:/jdbc/MySqlDS"). But I need it to be global so that other servlets, from other machines can use it. Which is when I added: <use-java-context>false</use-java-context> to my mysql-ds.xml file so that the default, local java:/ namespace won't be used. 
But now whenever the servlet is invoked I get the error that says MySqlDS not bound (complete trace shown below). 

Error I get when I try to invoke the servlet : 
16:34:47,328 ERROR [STDERR] javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.N 
ameNotFoundException: MySqlDS not bound] 
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067) 
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700) 
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:716) 
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) 
16:34:47,328 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351) 
16:34:47,328 ERROR [STDERR] at ReadServlet.doGet(ReadServlet.java:28) 
16:34:47,328 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697) 
16:34:47,328 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810) 
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCha 
in.java:252) 
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 
173) 
16:34:47,328 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) 
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCha 
in.java:202) 
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 
173) 
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) 
16:34:47,343 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValv 
e.java:175) 
16:34:47,343 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74) 
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) 
16:34:47,343 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) 
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) 
16:34:47,343 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) 
16:34:47,343 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) 
16:34:47,343 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection 
(Http11BaseProtocol.java:664) 
16:34:47,343 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) 
16:34:47,343 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:1 
12) 
16:34:47,343 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595) 
16:34:47,343 ERROR [STDERR] Caused by: javax.naming.NameNotFoundException: MySqlDS not bound 
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) 
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) 
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543) 
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:296) 
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625) 
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) 
16:34:47,343 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351) 
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061) 
16:34:47,343 ERROR [STDERR] ... 25 more 

service=jndiview - 

Global JNDI Namespace 

+- jdbc (class: org.jnp.interfaces.NamingContext) 
| +- MySqlDS (class: javax.sql.DataSource) 


Any ideas/suggestions? I?ve been stuck on this thing for almost 3 days now. 

Thanks!


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

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



More information about the jboss-user mailing list