FW: Database Assistance Needed

2005-04-16 Thread Folashade Adeyosoye
Ok let me give this a stab, this might help you

Please find the attached files, not sure if the attached file's makes its
way to the list



SampleCode = Sample code, that gets the connection etc
DBConnectionManager = manages the connection pool
DBUtil = DB utility
System.properties = configuration
DBoptions = DB options etc



All you have to do is change the system.properties to fit your need and
compile.



-Original Message-
From: Scott Purcell [mailto:[EMAIL PROTECTED] 
Sent: Friday, April 15, 2005 4:56 PM
To: user@struts.apache.org
Subject: 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 public boolean isMemberAvailableByUserName(String memberUserName) throws
  SQLException {

boolean memberPresent = false;
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);

sql.append("SELECT MemberUserName");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE MemberUserName = ?");

try {
  connection = DBUtils.getConnection();
  statement = connection.prepareStatement(sql.toString());
  statement.setString(1, memberUserName);
  resultSet = statement.executeQuery();
  if (resultSet.next()) {
memberPresent = true;
  }
}
catch (SQLException sqle) {
  sqle.printStackTrace();
  logger.fatal("Error executing " + sql + memberUserName);
}
finally {
  DBUtils.closeResultSet(resultSet);
  DBUtils.closeStatement(statement);
  DBUtils.closeConnection(connection);
}
return memberPresent;
  }

import java.sql.*;
import java.util.*;

import org.apache.commons.logging.*;


/**
 * DBConnectionManager
 *
 * This class is a Singleton that provides access to the
 * connection pool. A client gets access to the single
 * instance through the static getInstance() method
 * and can then check-out and check-in connections from a pool.
 * When the client shuts down it should call the release() method
 * to close all opened connections and do other clean up.
 */
public class DBConnectionManager {
/**
 * Logger
 */
private static Log logger = LogFactory.getLog(DBConnectionManager.class);

/**
 * TIME_BETWEEN_RETRIES
 */
private static final int TIME_BETWEEN_RETRIES = 500; // O.5 second

/**
 * DBConnectionManager instance
 */
static private DBConnectionManager instance = null;   // The single instance

/**
 * DBConnectionPool pool
 */
private DBConnectionPool pool = null;// please be careful if u want to make this variable static

  /**
   * A private constructor since this is a Singleton Note: This constructor is
   * lightweight since DBConnectionPool is lightweight, so no connection is
   * created until the first time getConnection() is called
   *
   * @param option DBOptions
   */
  private DBConnectionManager(DBOptions option) {
try {
Class.forName(option.driverClassName).newInstance();
} catch (Exception e) {
logger.fatal("DBConnectionManager: Unable to load driver = " + option.driverClassName);
}

//if (pool == null) {//uncomment since pool is an instance variable
pool = new DBConnectionPool(option.databaseURL, option.databaseUser, option.databasePassword, option.maxConnection);
//}
}

/**
 * Returns the single instance, creating one if it's the
 * first time this method is called.
 *
 * @return DBConnectionManager The single instance.

Re: How to create a web flow with Struts

2005-04-16 Thread Dakota Jack
Hi, Michael

After a quick look, I am trying to see how this is particularly
Struts.  You have a custom RequestProcessor that allows your stuff to
be used with Struts, but other than this, the general solutions seems
to be quite outside the Struts architecture.  Is that right, or do I
have it wrong?

Jack

On 4/15/05, Michael J. <[EMAIL PROTECTED]> wrote:
> Hi guys,
> I am using Struts for three years, but only now decided to join the
> user group. About the web flow: would you like to take a look at
> approach, alternative to Spring Web Flow? I started thinking on flow
> engines when IBM's Servlet Manager still was around, but only lately I
> came up with something decent.
> 
> I had looked at Struts Workflow Extension and had thought that I
> needed something simpler. So, here it is, the Easy Wizard:
> http://www.superinterface.com/easywizard.htm
> 
> I am updating the docs right now, but the Struts version is already
> pretty good (JSF integration works as well, but not as clean. Spring
> is next) Please, check out the live demo at:
> http://www.superinterface.com/wizard/signupWizard.do  Feel ree to
> reload, go forward or back. This is thing is pretty robust.
> 
> The how-to is in process, but there are two articles, which describe
> pretty well, what Easy Wizard is:
> http://today.java.net/pub/a/today/2005/03/15/webwizard1.htm and
> http://today.java.net/pub/a/today/2005/03/29/webwizard2.htm
> 
> I would like to hear comments from Struts community about my stuff.
> 
> Thanks,
>Michael.
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

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



getResources(HttpServletRequest) in ActionForm?

2005-04-16 Thread atta-ur rehman
Hi all,

Action class defines getResources(HttpServletRequest) method, thru
which I can get access to MessageResources.

I don't see an equivalant method in ActionForm. Is it possible to get
access to resource files in ActionForm subclasses? If so, how would I
do it?

Thanks.

ATTA

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



Re: getResources(HttpServletRequest) in ActionForm?

2005-04-16 Thread Michael J.
Action class defines getResources(HttpServletRequest) as follows:

protected MessageResources getResources(HttpServletRequest request) {
  return ((MessageResources) request.getAttribute(Globals.MESSAGES_KEY));
 }

I don't see why this method is not static. Hopefully, this will be
refactored. Anyway, I guess you can instanitate base Action class and
call this method on it. Or, simply cut its content to your own code,
reset() and validate() methods of form bean receive request as
parameter.

Michael.

On 4/16/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
> Hi all,
> 
> Action class defines getResources(HttpServletRequest) method, thru
> which I can get access to MessageResources.
> 
> I don't see an equivalant method in ActionForm. Is it possible to get
> access to resource files in ActionForm subclasses? If so, how would I
> do it?
> 
> Thanks.

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



Re: getResources(HttpServletRequest) in ActionForm?

2005-04-16 Thread Michael J.
Oh, it is protected. Then just cut and paste:
  return ((MessageResources) request.getAttribute(Globals.MESSAGES_KEY));

Michael.

On 4/16/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> Action class defines getResources(HttpServletRequest) method, thru
> which I can get access to MessageResources.
>
> I don't see an equivalant method in ActionForm. Is it possible to get
> access to resource files in ActionForm subclasses? If so, how would I
> do it?
>
> Thanks.

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



Re: getResources(HttpServletRequest) in ActionForm?

2005-04-16 Thread atta-ur rehman
Michael,

copy-n-paste worked! I did copy it to my BaseActionForm though!

thanks.

ATTA

On 4/16/05, Michael J. <[EMAIL PROTECTED]> wrote:
> Oh, it is protected. Then just cut and paste:
>   return ((MessageResources) request.getAttribute(Globals.MESSAGES_KEY));
> 
> Michael.
> 
> On 4/16/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > Action class defines getResources(HttpServletRequest) method, thru
> > which I can get access to MessageResources.
> >
> > I don't see an equivalant method in ActionForm. Is it possible to get
> > access to resource files in ActionForm subclasses? If so, how would I
> > do it?
> >
> > Thanks.
>

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