but you should heed what Chris said, regardless of whether this happened to 
work or not, because you're asking for further problems down the road with that 
configuration -- the try/catch block and everything else, too!

-----Original Message-----
From: Jason Ling [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 14, 2008 9:32 AM
To: Tomcat Users List
Subject: Re: DataSource binding for JSP


Chris,

Thanks for the notes.  It turned out the problem (data not retrieved from
the database) was not caused by the code, but by the tomcat server.  I
invoked the same jsp file and there was one more problem that the JDBC
driver could not be found.  I made sure the the jdbc jar file was in place
and rebooted the computer, and the same jsp file worked.

I am actually learning servlet and jsp.  The jsp file is an exercise from a
book but it uses the driver manager method (the forName() method) which I
changed to the DataSource method.

Your notes gave me the assurance that the DataSource declaration in
context.xml and the reference the the deployment descriptor are used by both
servlet files alike, whether it is written by us or translated from jsp.

Thanks again.

Jason



On Wed, Feb 13, 2008 at 6:33 PM, Christopher Schultz <
[EMAIL PROTECTED]> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Jason,
>
> Jason Ling wrote:
> | When the file is invoked,
> | it only returns the header row of the table (First Name, Last Name, User
> | Name, Password), but does not return the expected records from the
> Oracle
> | data table.
>
> [snip]
>
> | <%! DataSource ds; %>
>
> This is dangerous; you have a DataSource member, rather than a local.
> You should change this by removing the "!" so that this is a local
> variable. If you don't do this, you will run into threading problems.
>
> | <%
> |   try {
> |      Context initCtx = new InitialContext();
> |      Context envCtx = (Context) initCtx.lookup("java:comp/env");
> |      ds = (DataSource) envCtx.lookup("jdbc/DBDevTrackConnDS");
> |   } catch (NamingException e) {
> |      e.printStackTrace();
> |   }
> | %>
>
> Why do you allow processing to continue if there is an exception getting
> the DataSource? There is nothing useful your JSP can do if the
> DataSource is not successfully obtained. My guess is that you are
> getting a NullPointerException below...
>
> [snip]
>
> |   try {
> [snip]
> |     }
> [snip]
> |   }
> |   catch (SQLException e) {
> |   }
> |   catch (Exception e) {
> |   }
>
> ... which you can't see because you are swallowing all exceptions.
>
> | javax.naming.NameNotFoundException: Name jdbc is not bound in this
> Context
>
> This is another problem that is definitely the cause of your problems.
> It's good that you had this problem, so you'd ask a question and see all
> of the /other/ problems that you didn't know you had in the first place.
>
> | I have been using the same try{} blocks in my servlet files.
>
> Your try/catch idiom leaks connections, statements, and result sets. :(
> You should fix that, too.
>
> | The connection
> | to the same database has always be successful and the data records are
> | retrieved.  I figure that the only difference between the servlets and
> the
> | jsp is that the servlet has the binding information for the database
> in the
> | appName/META-INF/context.xml file:
>
> Why would you think that? Are you running your servlets and JSPs in
> different webapps? If not, then the context.xml file specifies setup for
> all servlets in a webapp (including those translated from JSP).
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkezfj0ACgkQ9CaO5/Lv0PBjIwCZAVMjTBygZj1iDvCNQY9hWKka
> xrMAn0/uF81TI4V1ydvJ+s1rbLndVAb9
> =Sn3x
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to