tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Les Hughes <leslie.hug...@rubus.com>
Subject RE: javax.naming.NamingException: Cannot create resource instance
Date Thu, 27 Jun 2002 09:19:26 GMT

Ok, I've had a chance to modify my msql example to work with Oracle. Here's
what I found

1) When using the thin driver, make sure that the SID is actually the SID,
not the TNS name of the service. If you're not sure, open your TNSNames.ora
and look for the service name, it should have a entry (SID = XXXX). Use this
as the SID.
Also try specifying the instance on the connect string as in

jdbc:oracle:thin:myinstance@somehost:1512:mysid

I'm not an oracle DB BTW - sorry if the terminology is wrong.

2) You need to remove the javax.sql.* classes from classes12.zip and rename
to classes12.jar. You also need commons.jar, pool.jar and collections.jar in
your common/lib directory.

Debug. If the driver is loading, the Datasource will be created. When you
hit your JSP, Tomcat will dump Ora errors to stdout. Use
$CATALINA_HOME/bin/catalina.bat run to keep the server running in a console
window to get at this dump.

If you see nothing then you have a classpath/driver not found kind of
problem.

So, try a get it to throw some SQLExceptions - that why we know that you're
at least finding the driver OK.

Keep trying - it does work in the end (honest!)

BTW I'm using TC 4.0.3 LE with JDK 1.4.0-b92 on W2K with classes12.zip
downloaded from OTN yesterday, against Oracle 8i

Les


> -----Original Message-----
> From: Vikramjit Singh [mailto:vikramjits@gtllimited.com]
> Sent: 27 June 2002 05:54
> To: 'Tomcat Users List'
> Subject: RE: javax.naming.NamingException: Cannot create resource
> instance
> 
> 
> Hi,
> 
> Just read a mail from Rick. Thanks to ur advice to remove 
> slash, i removed
> slash and thank god didnt get the error that
> 
> javax.naming.NamingException: Cannot create resource instance
> 
> Now my jsp page is displayed. Really dont know why it gave 
> error due to
> slash(/).
> 
> 
> But  one more problem, when i run the code, i dont get any 
> connection, coz
> it says DataSource is null. 
> 
> Am posting my code again.
> Here is my code in jsp. 
> 
> 	Context ctx = new InitialContext();
> 	if(ctx == null ) 
> 		throw new Exception("Boom - No Context");
> 
> 	DataSource ds = (DataSource) 
> ctx.lookup("java:comp/env/jdbc/ora");
> 	System.out.println(ds);
> 	if (ds != null) {
> 		Connection conn = ds.getConnection();
>               
>         if(conn != null)  {
> 			String foo = "Got Connection "+conn.toString();
>             Statement stmt = conn.createStatement();
>             ResultSet rst = stmt.executeQuery("select empno, 
> ename from
> emp");
> 			if(rst.next()) {				
> 				foo=rst.getString(2);
> 				System.out.println(foo);
> 			}
>             conn.close();
> 		}
> 	}
> 
> lines in server.xml
> 
>       <Context path="CorpMIS" docBase="CorpMIS" debug="0" 
> reloadable="true"
> crossContext="true"> 
> 	<Logger className="org.apache.catalina.logger.FileLogger"
>               prefix="CorpMIS_log." suffix=".txt"
>               timestamp="true"/>
> 		<Resource name="jdbc/ora" auth="Container"
> type="javax.sql.DataSource"/>
> 		<ResourceParams name="jdbc/ora">
> 		<parameter>
> 			<name>factory</name>
> 	
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> 	      </parameter>
> 	
> 	
> <parameter><name>maxActive</name><value>100</value></parameter>
> 	
> <parameter><name>maxIdle</name><value>30000</value></parameter>
> 	      
> <parameter><name>maxWait</name><value>100</value></parameter>
> 	
> <parameter><name>username</name><value>scott</value></parameter>
> 	
> <parameter><name>password</name><value>tiger</value></parameter>
> 
> 		<parameter>
> 	
> <name>driverClassName</name><value>oracle.jdbc.driver.OracleDr
> iver</value>
> 		</parameter>
> 		<parameter>
> 			<name>url</name>
> 			<value>jdbc:oracle:thin@eou3:1521:incub</value>
> 		</parameter>
> 		</ResourceParams>
>         </Context>
> 
> web.xml
> 
> <resource-ref>
> 	<description>Oracle Test App</description>
> 	<res-ref-name>jdbc/ora</res-ref-name>
> 	<res-type>javax.sql.DataSource</res-type>
> 	<res-auth>Container</res-auth>
> </resource-ref>
> 
> Regards,
> Vikramjit Singh,
> Systems Engineer,
> GTL Ltd.
> Ph. 7612929-1031
> 
> 
> -----Original Message-----
> From: Les Hughes [mailto:leslie.hughes@rubus.com]
> Sent: Wednesday, June 26, 2002 3:25 AM
> To: 'Tomcat Users List'
> Subject: RE: javax.naming.NamingException: Cannot create resource
> instance
> 
> 
> 
> Yet more digging about in CVS.... Perhaps one of the TC devs 
> can confirm
> this but it seems that 
> org.apache.catalina.startup.ClassLoaderFactory.java
> prior to V1.6 used to drop any jarfiles that contain classes 
> from (amongst
> others) javax.sql.* This means that if your version of TC has 
> this code,
> your classes12.zip (which has javax.sql) will not be loaded at all.
> 
> So, I suggest, for JDK1.4, you either (a) upgrade to a recent 
> version of
> TC4.0 or TC4.1 (not too sure which versio of TC has 
> ClassLoaderFactory.java
> > 1.6) or (b) unjar classes12.zip and remove the javax.sql 
> stuff, re-jar and
> try again.
> 
> As I said, this is all supposition - perhaps a developer with 
> a bit more
> knowledge of the codebase could confirm?
> 
> es
> 
> > -----Original Message-----
> > From: Les Hughes [mailto:leslie.hughes@rubus.com]
> > Sent: 26 June 2002 10:58
> > To: 'Tomcat Users List'
> > Subject: RE: javax.naming.NamingException: Cannot create resource
> > instance
> > 
> > 
> > RPM - Redhat Package Manager - it's a bit like the windows 
> > installer but for
> > Unix/Linux.
> > 
> > Have you tried a 1.2/1.3 JVM? See my post yesterday regarding 
> > Oracle/VM/JDBC
> > drivers and versions - I'm not sure if classes12.zip is OK 
> > for 1.4 - someone
> > mentioned that this zip has the javax.sql classes now present 
> > in the core VM
> > and they don't co-exist nicely..(perhaps someone else can 
> > verify this?)
> > 
> > Also, you server.xml seems to be incomplete - you haven't 
> > provided all of
> > the pool settings for DBCP. Again, not sure if this is important...
> > 
> > Les
> > 
> > 
> > 
> > > -----Original Message-----
> > > From: Vikramjit Singh [mailto:vikramjits@gtllimited.com]
> > > Sent: 26 June 2002 08:16
> > > To: 'Tomcat Users List'
> > > Subject: RE: javax.naming.NamingException: Cannot create resource
> > > instance
> > > 
> > > 
> > > i do have classes12.jar in my /common/lib directory. 
> > > Have done everything as suggested to me by your replies and links.
> > > Still its not working seems like things will work on 4.1 :(. 
> > > For now, cant
> > > think of whats wrong.
> > > By the way
> > > Whats RPM??.
> > > 
> > > Regards,
> > > Vikramjit Singh,
> > > Systems Engineer,
> > > GTL Ltd.
> > > Ph. 7612929-1031
> > > 
> > > 
> > > -----Original Message-----
> > > From: Manolo Ramirez [mailto:manolo@seafbo.com]
> > > Sent: Tuesday, June 25, 2002 8:21 AM
> > > To: Tomcat Users List
> > > Subject: Re: javax.naming.NamingException: Cannot create resource
> > > instance
> > > 
> > > 
> > > I got the same problem with PostgreSQL, it was because the 
> > > RPM of Tomcat
> > > 4.0.3 
> > > does not support Tyrex, I had to compile the source RPM and 
> > > install all the 
> > > requirements to work.
> > > 
> > > To verify try loading this Classes:
> > > 
> > > import tyrex.jdbc.ServerDataSource;
> > > import tyrex.jdbc.xa.EnabledDataSource;
> > > 
> > > if don't load you must to recompile Tomcat.
> > > 
> > > 
> > > -- 
> > > Manolo G. Ramirez T.
> > > Serinbol S.A.
> > > 
> > > On Mar 25 Jun 2002 00:42, Vikramjit Singh wrote:
> > > > hi,
> > > >
> > > > I am using tomcat 4.0.3 and the same problem i am facing 
> > > though i am using
> > > > Oracle driver i.e. classes12.zip. I have tried the code in 
> > > the url you
> > > > specified and i am also using tomcat 4.0.3 and jdk1.4.
> > > >
> > > > I get the error
> > > >
> > > > javax.naming.NamingException: Cannot create resource instance
> > > > 	at
> > > >
> > > org.apache.naming.factory.ResourceFactory.getObjectInstance(Re
> > > sourceFactory
> > > >. java:167
> > > >
> > > > here is what i have written in server.xml.
> > > >
> > > >
> > > > 		<Resource name="jdbc/ora" auth="Container"
> > > > type="javax.sql.DataSource"/>
> > > > 		<ResourceParams name="jdbc/ora">
> > > > 		<parameter>
> > > > 			<name>factory</name>
> > > >
> > > > <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> > > > 	      </parameter>
> > > > 		<parameter>
> > > > 		<name>username</name>
> > > > 		<value>scott</value>
> > > > 		</parameter>
> > > > 		<parameter>
> > > > 		<name>password</name>
> > > > 		<value>tiger</value>
> > > > 		</parameter>
> > > > 		<parameter>
> > > > 		<name>driverClassName</name>
> > > > 		<value>oracle.jdbc.driver.OracleDriver</value>
> > > > 		</parameter>
> > > > 	        <parameter>
> > > > 			<name>driverName</name>
> > > > 			
> <value>jdbc:oracle:thin:@eou3:1521:incub</value>
> > > > 		</parameter>
> > > > 		<parameter>
> > > > 			<name>url</name>
> > > > 			
> <value>jdbc:oracle:thin:@eou3:1521:incub</value>
> > > > 		</parameter>
> > > > 		</ResourceParams>
> > > >
> > > > Is the driverName correct. If someone is using 
> > > classes12.zip could someone
> > > > tell whats the correct settings, if mine is wrong.
> > > > in web.xml have written as told.
> > > >
> > > > the jsp has this
> > > >
> > > > <%
> > > > try {
> > > > 	Context ctx = new InitialContext();
> > > > 	if(ctx == null )
> > > > 		throw new Exception("Boom - No Context");
> > > >
> > > > 	DataSource ds = (DataSource) 
> > > ctx.lookup("java:comp/env/jdbc/ora");
> > > > 	if (ds != null) {
> > > > 		Connection conn = ds.getConnection();
> > > >
> > > >         if(conn != null)  {
> > > > 			String foo = "Got Connection 
> "+conn.toString();
> > > >             Statement stmt = conn.createStatement();
> > > >             ResultSet rst = stmt.executeQuery("select 
> > > empno, ename from
> > > > emp");
> > > > 			if(rst.next()) {
> > > > 				foo=rst.getString(2);
> > > > 			}
> > > >             conn.close();
> > > > 		}
> > > > 	}
> > > > }
> > > > catch (SQLException E) {
> > > > 	out.println("<br>unable to get connection on ora !");
> > > > 	out.println("<br>SQLException: " + E.getMessage());
> > > > 	out.println("<br>SQLState: " + E.getSQLState());
> > > > 	out.println("<br>VendorError: " + E.getErrorCode());
> > > > }
> > > > %>
> > > >
> > > > Regards,
> > > > Vikramjit Singh,
> > > > Systems Engineer,
> > > > GTL Ltd.
> > > > Ph. 7612929-1031
> > > >
> > > >
> > > > -----Original Message-----
> > > > From: Jacob Kjome [mailto:hoju@visi.com]
> > > > Sent: Monday, June 24, 2002 8:04 AM
> > > > To: Tomcat Users List
> > > > Subject: Re: javax.naming.NamingException: Cannot 
> create resource
> > > > instance
> > > >
> > > >
> > > > Hello Kumar,
> > > >
> > > > Try using the "username" parameter.
> > > >
> > > > Also, the solution that has worked flawlessly for me is here:
> > > >
> > > > 
> http://marc.theaimsgroup.com/?l=tomcat-user&m=102225547106556&w=2
> > > >
> > > > Note that this is with the new 4.1.x versions of Tomcat.  
> > If you are
> > > > using 4.0.x versions, your mileage may vary.
> > > >
> > > > Jake
> > > >
> > > > Monday, June 24, 2002, 10:00:38 AM, you wrote:
> > > >
> > > > K> Hi,
> > > > K>    Can anyone help me how to configure JDBC DataSource 
> > > using IBM DB2 as
> > > > the
> > > > K> database.I had gone through the solution "Generic 
> > > DataSource Resource
> > > > K> Factory Available. JDBC Data Sources." posted by 
> > > Mr.Anthony Dodd.But
> > > > there
> > > > K> the solution was explained using Oracle database.Has 
> > anyone tried
> > > > K> configuring a DataSource using DB2?
> > > >
> > > > K> I'm using IBM DB2  7.1 (Driver - 
> > COM.ibm.db2.jdbc.app.DB2Driver)
> > > > K> Tomcat 4.0.2
> > > >
> > > > K> Here are the snippets for server.xml,web.xml and the JVM 
> > > stack trace:
> > > >
> > > > K> server.xml:
> > > >
> > > > K>     <Context path="/test" docBase="test" debug="0" 
> > > reloadable="true">
> > > > K>   <Resource name="jdbc/myDS" 
> > > type="COM.ibm.db2.jdbc.DB2DataSource"
> > > > K> reloadable="true" auth="Container"/>
> > > > K>   <ResourceParams name="jdbc/myDS">
> > > > K>    <parameter>
> > > > K>     <name>factory</name>
> > > > K>     
> <value>org.apache.naming.factory.DataSourceFactory</value>
> > > > K>    </parameter>
> > > > K>    <Parameter>
> > > > K>     <name>user</name>
> > > > K>     <value>db2admin</value>
> > > > K>    </Parameter>
> > > > K>    <Parameter>
> > > > K>     <name>password</name>
> > > > K>     <value>db2admin</value>
> > > > K>    </Parameter>
> > > > K>    <Parameter>
> > > > K>     <name>driverClassName</name>
> > > > K>     <value>COM.ibm.db2.jdbc.app.DB2Driver</value>
> > > > K>    </Parameter>
> > > > K>    <Parameter>
> > > > K>     <name>driverName</name>
> > > > K>     <value>jdbc:db2:sample</value>
> > > > K>    </Parameter>
> > > > K>   </ResourceParams>
> > > >
> > > > K>   <Realm  className="org.apache.catalina.realm.JDBCRealm"
> > > > K>      connectionName="db2admin"
> > > > K>      connectionPassword="db2admin"
> > > > K>      connectionURL="jdbc:db2:sample"
> > > > K>      digest="SHA"
> > > > K>      driverName="COM.ibm.db2.jdbc.app.DB2Driver"
> > > > K>      roleNameCol="role_name"
> > > > K>      userCredCol="password"
> > > > K>      userNameCol="user_name"
> > > > K>      userRoleTable="user_roles"
> > > > K>      userTable="users" />
> > > > K>  </Context>
> > > >
> > > > K> web.xml:
> > > >
> > > > K>  <resource-ref>
> > > > K>   <description>DS resource factory</description>
> > > > K>   <res-ref-name>jdbc/myDS</res-ref-name>
> > > > K>   <res-type>COM.ibm.db2.jdbc.DB2DataSource</res-type>
> > > > K>   <res-auth>Container</res-auth>
> > > > K>  </resource-ref>
> > > >
> > > > K> I get the following error when i try to lookup the 
> > > datasource in my
> > > JSP:
> > > > K> ctx (java:comp/env) = org.apache.naming.NamingContext@42a80d
> > > > K> obj = myDS: org.apache.naming.ResourceRef
> > > > K> Error processing the request (doGet)  : Cannot create 
> > > resource instance
> > > > K> javax.naming.NamingException: Cannot create resource instance
> > > > K>         at
> > > > 
> > > org.apache.naming.NamingContext.lookup(NamingContext.java:837)
> > >  K>        
> > > > at 
> > org.apache.naming.NamingContext.lookup(NamingContext.java:181) K>
> > > 
> > > >  at 
> > > org.apache.naming.NamingContext.lookup(NamingContext.java:822) K>
> > > 
> > > >   at 
> > > org.apache.naming.NamingContext.lookup(NamingContext.java:194) K>
> > > 
> > > >    at CheckDBServlet.doGet(CheckDBServlet.java:40)
> > > > K>         at
> > > javax.servlet.http.HttpServlet.service(HttpServlet.java:1125)
> > > > K>         at
> > > javax.servlet.http.HttpServlet.service(HttpServlet.java:1264)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilt
> > > er(Applicatio
> > > >n K> FilterChain.java:247)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.ApplicationFilterChain.doFilter(Appli
> > > cationFilterC
> > > >h K> ain.java:193)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardWrapperValve.invoke(StandardW
> > > rapperValve.j
> > > >a K> va:243)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invokeNext(StandardP
> > > ipeline.java:
> > > >5 K> 66)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invoke(StandardPipel
> > > ine.java:472)
> > > > K>         at
> > > > K> 
> > > 
> > 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardContextValve.invoke(StandardC
> > > ontextValve.j
> > > >a K> va:215)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invokeNext(StandardP
> > > ipeline.java:
> > > >5 K> 66)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.authenticator.AuthenticatorBase.invoke(Aut
> > > henticatorBas
> > > >e K> .java:472)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invokeNext(StandardP
> > > ipeline.java:
> > > >5 K> 64)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invoke(StandardPipel
> > > ine.java:472)
> > > > K>         at
> > > > K> 
> > > 
> > 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> > > > K>         at
> > > > K>
> > > > 
> > > org.apache.catalina.core.StandardContext.invoke(StandardContex
> > > t.java:2366)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardHostValve.invoke(StandardHost
> > > Valve.java:16
> > > >4 K> )
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invokeNext(StandardP
> > > ipeline.java:
> > > >5 K> 66)
> > > > K>         at
> > > > K>
> > > > 
> > > org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValv
> > > e.java:462)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invokeNext(StandardP
> > > ipeline.java:
> > > >5 K> 64)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invoke(StandardPipel
> > > ine.java:472)
> > > > K>         at
> > > > K> 
> > > 
> > 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardEngineValve.invoke(StandardEn
> > > gineValve.jav
> > > >a K> :163)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invokeNext(StandardP
> > > ipeline.java:
> > > >5 K> 66)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.core.StandardPipeline.invoke(StandardPipel
> > > ine.java:472)
> > > > K>         at
> > > > K> 
> > > 
> > 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.connector.http.HttpProcessor.process(HttpP
> > > rocessor.java
> > > >: K> 1005)
> > > > K>         at
> > > > K>
> > > >
> > > org.apache.catalina.connector.http.HttpProcessor.run(HttpProce
> > > ssor.java:109
> > > >8 K> )
> > > > K>         at java.lang.Thread.run(Thread.java:484)
> > > >
> > > > K> Thanks,
> > > > K> Srinivas Kumar
> > > >
> > > >
> > > > K> --
> > > > K> To unsubscribe, e-mail:
> > > > <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> > > > K> For additional commands, e-mail:
> > > > <mailto:tomcat-user-help@jakarta.apache.org>
> > > 
> > > 
> > > --
> > > To unsubscribe, e-mail:
> > > <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> > > For additional commands, e-mail:
> > > <mailto:tomcat-user-help@jakarta.apache.org>
> > > 
> > > --
> > > To unsubscribe, e-mail:   
> > <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> > <mailto:tomcat-user-help@jakarta.apache.org>
> > 
> > --
> > To unsubscribe, e-mail:   
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:tomcat-user-help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:tomcat-user-help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:   
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message