You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Scott Purcell <sp...@vertisinc.com> on 2005/04/15 22:55:46 UTC

Database Assistance Needed

I have had some issues this past week, trying to come up with a way to cleanly connect to my, MySQL database. I know this is not necessarily a struts issue, but I am betting that there is no one on this list who is not using some type of database in the back-end.

Now I have the O'Reilly book on Struts, and using the ObjectRelationalBridge is a little too large for me to take on currently, same as Hibernate or anything else I would have to research thoroughly. I just need a solid, simple way to grab a connection from a pool, use it in a Business Object and call it a day.  Since I am running on Tomcat 5.5, I have tried to incorporate the DBCP from jakarta into my struts stuff. Problem is most examples do not work, or are incomplete for the 5.5 Tomcat, and I cannot find any decent examples of doing this.

I am basically Running Mysql, and Tomcat 5.5, and struts 1.2. I really do not want to use the data-source in struts, as I intend to use a solution that will not be depreciated in the next release. Could anyone throw me a bone here. I have searched google to death for good examples, but come up with outdated examples, or incomplete. The examples for Tomcat make you use JNDI, and I am not sure if that is the way to go.

Any assistance would be sincerely appreciated.

Thanks,
Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Database Assistance Needed

Posted by Erik Weber <er...@mindspring.com>.
JNDI *is* the way to go. See the Tomcat doc on configuring a DataSource 
(cited below). I use Tomcat 5.0, but I will not buy it that the examples 
don't work because I have followed the Tomcat documentation many times 
with success (including MySQL).

Then write a simple Java class that acts as a connection manager. Your 
business object uses a DAO (preferably by referring only to an interface 
so it's not affected when you switch data stores). Your DAO asks the 
connection manager for a connection, either via a static method or an 
instance method if you are using a singleton. Your connection manager 
uses a JNDI lookup to get a reference to the DataSource that was 
configured in your application's context XML file (use caching so that 
the lookup only has to happen once). Try to get a connection from the 
DataSource. If that fails, use DriverManager to get a connection so the 
application will work, but log the error and fix the DataSource. No. 1 
problem is a JNDI lookup on the wrong name.

There is a MySQL example on this page:

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html


Erik



Scott Purcell wrote:

>I have had some issues this past week, trying to come up with a way to cleanly connect to my, MySQL database. I know this is not necessarily a struts issue, but I am betting that there is no one on this list who is not using some type of database in the back-end.
>
>Now I have the O'Reilly book on Struts, and using the ObjectRelationalBridge is a little too large for me to take on currently, same as Hibernate or anything else I would have to research thoroughly. I just need a solid, simple way to grab a connection from a pool, use it in a Business Object and call it a day.  Since I am running on Tomcat 5.5, I have tried to incorporate the DBCP from jakarta into my struts stuff. Problem is most examples do not work, or are incomplete for the 5.5 Tomcat, and I cannot find any decent examples of doing this.
>
>I am basically Running Mysql, and Tomcat 5.5, and struts 1.2. I really do not want to use the data-source in struts, as I intend to use a solution that will not be depreciated in the next release. Could anyone throw me a bone here. I have searched google to death for good examples, but come up with outdated examples, or incomplete. The examples for Tomcat make you use JNDI, and I am not sure if that is the way to go.
>
>Any assistance would be sincerely appreciated.
>
>Thanks,
>Scott
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org