Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 85353 invoked from network); 26 Jan 2010 05:55:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Jan 2010 05:55:18 -0000 Received: (qmail 10777 invoked by uid 500); 26 Jan 2010 05:55:14 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 10626 invoked by uid 500); 26 Jan 2010 05:55:13 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 10615 invoked by uid 99); 26 Jan 2010 05:55:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jan 2010 05:55:12 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [71.74.56.124] (HELO hrndva-omtalb.mail.rr.com) (71.74.56.124) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jan 2010 05:55:03 +0000 X-Authority-Analysis: v=1.0 c=1 a=VLrcWpuryDMA:10 a=-57I09spAAAA:8 a=mV9VRH-2AAAA:8 a=xe8BsctaAAAA:8 a=OFeCXs34uAoouR7m2O0A:9 a=sA2dOPR8hAP0YC9c9mMA:7 a=T1kTgpDMeBN9jDnw4W3Q2CLzH7sA:4 a=EnLKqdGQ194A:10 X-Cloudmark-Score: 0 X-Originating-IP: 70.112.194.176 Received: from [70.112.194.176] ([70.112.194.176:1943] helo=JSR2006) by hrndva-oedge03.mail.rr.com (envelope-from ) (ecelerity 2.2.2.39 r()) with ESMTP id F4/DD-19161-1A38E5B4; Tue, 26 Jan 2010 05:54:41 +0000 Message-ID: From: "Steve Ryder" To: "Tomcat Users List" References: <67FCB5CF09B74E9C97D6A934448C7E48@JSR2006> <99C8B2929B39C24493377AC7A121E21F9683764534@USEA-EXCH8.na.uis.unisys.com> <4B05DAA048F04E3EBFE9D592704471D7@JSR2006> <4B5DDDFD.2070704@christopherschultz.net> <4CEFF541FAD947F7A727E1A40B231CA5@JSR2006> <4B5E01D3.4000404@christopherschultz.net> Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource Date: Mon, 25 Jan 2010 23:08:16 -0600 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5843 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Sequence of events: 1) With factory got cast error. 2) Took out factory= and got "Cannot create resource instance" 3) Put factory statement back in. Is there a different one I should try? The cast exception is Thrown by this line javax.sql.DataSource ds = (javax.sql.DataSource)envContext.lookup("jdbc/MySql"); in the connect method. Here is the whole method as of the last test: /** * called by setDataBaseName */ private void connect(String dbName) { lastException = "OK"; /* don't need this if have connection pools try { // Class.forName("org.gjt.mm.mysql.Driver"); sysout.display("Driver=com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver"); } catch (Exception E) {lastException=" Unable to load driver"; E.printStackTrace(); sysout.display(lastException);} */ try { sql = "Connection to jdbc/MySql:"; Context myContext = new InitialContext(); Context envContext = (Context)myContext.lookup("java:comp/env"); sysout.display("JsrSQL: Context cast successfull"); javax.sql.DataSource ds = (javax.sql.DataSource)envContext.lookup("jdbc/MySql"); sysout.display("JsrSQL: DataSource cast successfull"); conn = ds.getConnection(); sysout.display("JsrSQL: conn = ds successfull"); stmt = conn.createStatement(); sql = "USE "+ dbName; // attempt to mymic jdbcConnect set for dbName! stmt.execute(sql); sysout.display("**"+sql + ": connection to jdbc/MySql established."); } catch (SQLException E) { lastException="*WARNING*"+sql+ ": connect SQL exception: " + E.getMessage(); sysout.display(lastException); } catch(Exception eOther) { StackTraceElement[] stack = eOther.getStackTrace(); for (int s=0; s < stack.length; s++) { lastException = "Stack("+s+")=" + stack[s]; sysout.display(lastException); if (lastException.indexOf("org.apache.jasper") > -1) break; } lastException="*WARNING*"+sql+ ": connect Other exception: " + eOther.getMessage(); sysout.display(lastException); } } ----- Original Message ----- From: "Christopher Schultz" To: "Tomcat Users List" Sent: Monday, January 25, 2010 2:40 PM Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Steve, > > On 1/25/2010 2:56 PM, Steve Ryder wrote: >> Starting from the bottom up of your suggestions: >> 1) I tried removing the try/catch. No can do, Java compiler forces me >> to catch the exceptions. > > Hmm... what method is declared as throwing "Exception" instead of > something more specific? > >> 2) However, Java does provide a getStackTrace. > > Throwable.printStackTrace() will also do the trick. > >> 2010-01-25 >> 19:37:09:Stack(5)javax.servlet.http.HttpServlet.service(HttpServlet.java:802) >> >> 2010-01-25 >> 19:37:09:Stack(4)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) >> >> 2010-01-25 >> 19:37:09:Stack(3)org.apache.jsp.index_jsp._jspService(index_jsp.java:89) >> 2010-01-25 19:37:09:Stack(2)com.jsrsys.web.JsrSQL.(JsrSQL.java:42) >> 2010-01-25 >> 19:37:09:Stack(1)com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86) >> 2010-01-25 >> 19:37:09:Stack(0)com.jsrsys.web.JsrSQL.connect(JsrSQL.java:503) > > Is this the code you posted earlier? If so, which line is 503? > >> 2010-01-25 19:37:09:*WARNING*Connection to jdbc/MySql:: connect Other >> exception: org.apache.naming.ResourceRef cannot be cast to >> javax.sql.DataSource > > This isn't the error message you posted earlier. The one you posted > earlier was: > > " > 2010-01-25 15:56:06:*WARNING*Connection to jdbc/MySql:: connect Other > exception: Cannot create resource instance > " > >> Removing the Class.forName code did not change anything, I still get >> the same error. > > Right: the Class.forName simply wasn't necessary... I didn't expect it > to change anything. > >> 2010-01-25 20:00:03:*WARNING*Connection to jdbc/MySql:: connect Other >> exception: org.apache.naming.ResourceRef cannot be cast to >> javax.sql.DataSource >> >> 2010-01-25 >> 20:00:03:Stack(4)=org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) >> 2010-01-25 >> 20:00:03:Stack(3)=org.apache.jsp.index_jsp._jspService(index_jsp.java:89) >> 2010-01-25 20:00:03:Stack(2)=com.jsrsys.web.JsrSQL.(JsrSQL.java:42) >> 2010-01-25 >> 20:00:03:Stack(1)=com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86) >> 2010-01-25 >> 20:00:03:Stack(0)=com.jsrsys.web.JsrSQL.connect(JsrSQL.java:504) >> 2010-01-25 20:00:03:JsrSQL: Context cast successfull > > Could you re-post the whole method? The object you get from the JNDI > context really /should/ be a javax.sql.DataSource object, not a > ResourceLink. > > - -chris > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAkteAdMACgkQ9CaO5/Lv0PAm7wCfSWyuzVUbJ1zXqaruicFBoUnS > R6wAn3JGjRZ7uMS5uf1tR8utZ7oWnzpT > =ymR0 > -----END PGP SIGNATURE----- > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org > For additional commands, e-mail: users-help@tomcat.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org