Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes javax.naming.NamingException- Cannot create resource instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "javax.naming.NamingException- Cannot create resource instance" Watch "javax.naming.NamingException- Cannot create resource instance" New topic
Author

javax.naming.NamingException- Cannot create resource instance

Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
Greetings,
i am getting this exception while i am trying to connect oracle database thru JNDI. The oracle jdbc driver is availavle in %CATALINA-HOME/common/lib as well as in my application context directory under WEB-INF(/lib).
I have given below my codings for reference.
This is my context in server.xml.
<!-- MyServlets Context-->
<Context path="/MyServlets" docBase="MyServlets" debug="0"
reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_MyServlets_log." suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/test" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/test">
<parameter><name>user</name><value>scott</value></parameter>
<parameter><name>password</name><value>tiger</value></parameter>
<parameter><name>driverClassName</name>
<value>jdbc racle:thin:@localhost:1521:test</value></parameter>
<parameter><name>driverName</name>
<value>oracle.jdbc.driver.OracleDriver</value></parameter>
</ResourceParams>
</Context>
<!-- End of MyServlets Context -->
My application web.xml.
<resource-ref>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and this is my JDBC connection part of my code,
try{
InitialContext ctx= new InitialContext();
DataSource ds=(DataSource) ctx.lookup("java:comp/env/jdbc/test");
conn=ds.getConnection();
}
anybody could help me out to solve this problem?.
thanks in advance.
regards,
ravi.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

value tag jdbc racle:thin:@localhost:1521:test
i feel it should be
"jdbc: oracle:thin:@localhost:1521:test"
[ August 29, 2003: Message edited by: Pradeep Bhat ]

Groovy
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Pradeep, he probably only forgot to check the "disable smilies in this post" checkbox...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
thanks pradeep for your reply,
for your info, it is only a spelling mistake while editing my post, sorry for that.The url is given correctly as you said.
expecting your suggestions.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Try adding a resource factory parameter (just guessing here...) as follows:

[ August 29, 2003: Message edited by: Lasse Koskela ]
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
thanks lasse,
i tried out by adding the factory parameter as you suggested, but the server could not find the resource factory. The state of exception is,
javax.naming.NamingException- Could not create resource factory ClassNotFoundException.
i have taken out oracleDriver.class by unzipping classes12.zip and converted it into a jar file, since tomcat does not load zip files. Is that the right way? or
Is there anything related to classpath settings?
awating your reply,
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
i tried out by adding the factory parameter as you suggested, but the server could not find the resource factory. The state of exception is,
javax.naming.NamingException- Could not create resource factory ClassNotFoundException.

Didn't the stack trace indicate which class was not found? If it's the commons resource factory class that's missing, then you must be running Tomcat 3.x? I assumed that you're using 4.x when suggesting the factory class entry... Then again, if it's the Oracle driver class that's missing, you need to put classes12.zip into "TOMCAT_HOME/lib" or "WEB-INF/lib".
i have taken out oracleDriver.class by unzipping classes12.zip and converted it into a jar file, since tomcat does not load zip files.

I haven't heard of this before. A .jar file is basically a .zip file which includes a META-INF/MANIFEST.MF file and the manifest file doesn't need to contain anything special so most products read .zip files just as well as .jar files.
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
quote:
---------------------------------------------------------------------------
I haven't heard of this before. A .jar file is basically a .zip file which includes a META-INF/MANIFEST.MF file and the manifest file doesn't need to contain anything special so most products read .zip files just as well as .jar files.
---------------------------------------------------------------------------
Lasse, for your information i have given these few lines from tamcat-docs(jndi-datasource-howto.html availbale in TOMCAT-HOME/tomcat-docs)and that is why i decided to convert the zip files into jar files.
" Firstly by default, Tomcat will only use *.jar files installed in $CATALINA_HOME/common/lib therefore classes111.zip or classes12.zip will need to be renamed with a .jar extension. Since jarfiles are zipfiles, there is no need to unzip and jar these files - a simple rename will suffice. Also, you should be aware that some (early) versions of Tomcat 4.0 when used with JDK 1.4 will not load classes12.zip unless you unzip the file, remove the javax.sql.* class heirarchy and rejar."
and in the tomcat docs itself they have mentioned only jar files.
http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html
and yes i am using tomcat4.1 as well.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.naming.NamingException- Cannot create resource instance
 
Similar Threads
JDBC-CONNECTION POOL
javax.naming.NamingException- Cannot create resource instance
Configuring DataSource on Tomcat5.0
How Tomcat Works: connection pooling in tomcat
Tomcat Database Connection Pooling Error