Tom

> In a servlet you have an init() statement
> that executes only once which you get your
> db connection in...

I hope you are not in a fog about this: there is nothing pre-ordained about
getting a connection in a servlet init method - that just happens to be
where your code is.

> also you need to call super.init(config), where
> you don't have to do this in a bean, because it
> is implicit...

Hmm... I think maybe you are in a bit of fog about all this :-)

Calling 'super.init( config )' within a servlet's init method has nothing to
do with database connections.

Anyway, if you are prepared to post the *exact* bean code that is not
working for you, I am prepared to look at it and try to help you.

Posting snippets of code is not good enough.

The alternative is for you to walk through your code (with println
statements, or a debugger) and see where it stops working.

> Next challenge is I have a blob that I
> set and get, but when I get the blob on
> my results page, it comes up with...

Is that the servlet providing the 'results' - or did you fix the bean?

Regards

Harry


> Not exactly...it is not the same! I have it working with a connection
> pool, mySQL and JNDI. To keep my reply short it goes like this within
> the bean:
> getDBConnection();             // get
> the connection
> prepareStatement();         // prepare the
> statement
> rs = pstmt.executeQuery();    // execute the
> query
> and of course after that I "get" my parameters. In a servlet you have an
> init() statement that executes only once which you get your db
> connection in, also you need to call super.init(config), where you don't
> have to do this in a bean, because it is implicit.
> 
> (By the way, if someone wants an example, I will post it, but you'll
> then be my wife.)
> 
> Next challenge is I have a blob that I set and get, but when I get the
> blob on my results page, it comes up with something like this  @1eb2473
> which I assume is an address. Anyone know what know how to get, what's
> in the address. Maybe open a "stream"?
> 
> TIA
> 
> Tom K.
> 
> 
> 
> -----Original Message-----
> From: Harry Mantheakis [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 26, 2004 10:43 AM
> To: Tomcat Users List
> Subject: Re: Question on debuggin JNDI/prepared statement in a bean
> 
> 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