Hi Tom

> how do you set up a JNDI connection
> in a bean?

Exactly the same way as you would anywhere else, so if you have some code
working in a servlet, copy it.

To be precise, it is a database connection, acquired from a DataSource,
which is itself acquired via a JNDI lookup. The fact that your code is in a
bean makes no difference.


> how do you... use a prepared statement (in a bean)


Same as anywhere else.


> how do you... retrieve a resultset, and
> forward the result


Again, same as anywhere else.

BTW - you should not be passing about references to JDBC objects that are
tethered (so to speak) to database connections - it is bad practice, and
likely to cause connection (and memory) leaks.

The best thing to do with database connections is, grab your data, store it
in some collection object, and then make damn sure you close the db
connection - usually within a 'finally' block which is guaranteed to
execute, even when exceptions occur.

Having stored the data you need in a collection object, you can pass that
about as much as you like.

That has not really answered your original question, but unless you provide
us with all your relevant code we probably cannot solve the problem.

Since you got it working before, I would be inclined to start again, making
sure that you copy the same JNDI/connection procedures in your 'bean' as in
the servlet that works.

The fact that your 'bean' is not throwing any exceptions suggests, to me,
that there is a bug (logic error) in your code. Starting over might sort
that out.

Sprinkle about a few (temporary) 'System.out.println' statements to see
where your code gets to. Not cool, but they do the job sometimes!

If you are using an IDE - like Eclipse - you can run in debug mode, so it's
easy to see what is happening - though may be not with JSPs.

Good luck.

Harry


> Harry,
> 
> Yes the ClassifiedAd and UniqueDateId are two parameters taken
> from an html form, the values of ClassifiedAd and UniqueDateId are used
> in a prepared statement for substitution of ? and ? the results are then
> forwarded to a results jsp, which used the getXXX() to retrieve the
> values from the bean.
> I have this code working in another form as a Servlet using JNDI
> and prepared statements. In the servlet the JNDI connection is made in
> the init(blah, blah) and calls the super.init(config) which I
> super.init(config) is implicit from reading the Tomcat docs.
> The bottom line on this, is how do you set up a JNDI connection
> in a bean, use a prepared statement (in a bean), retrieve a resultset
> and forward the result for the results jsp to retrieve the value from
> the bean.
> 
> Finally, I apologize to those who feel this is off topic. I have similar
> code working in Resin but for the life of me, I can't get it working
> with Tomcat 5  :-(   I searched all the archives and can't find a good
> example for doing this.
> 
> TIA Tom K.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to