It is not a Struts problem.  But, it is the problem I
encounter in my Struts application.  Please help.  I
am NOT showing all my code.  For example, I skip the
DAO interface, and the class that returns a connection
object from the connection pool.  Nonetheless, those
classes are irrelevant to my question.

The root of my problem is that I do not know how to
pass data that are wrapped in a business bean in
between classes.  THE JAVA COMPILER DOES NOT RECOGNIZE
THE BUSINESS BEAN!

1. I have a controller Servlet that reads the
"username" that is supplied by a visitor of the web
site. I want to search the database by the "username"
and get some information about that user; such as
userrole, category, etc. A business bean sits in
between the controller servlet and the database. Here
is the partial code of the controller servlet:
[code]
// the statement below has problems
EditorBean editorData;
// Obtain username and password from web tier
String username = request.getParameter( username );
// find the editor's information via the business tier

// Again, the parameters that I supplied in the method
below have problems
EditorBean editor = EditorBean.findEditorData(
username, editorData );
// wrap the information found in the database in a
session object and go on
HttpSession session = request.getSession();
editor.setUserrole( request.getParameter( "userrole" )
);
editor.setCategory( request.getParameter( "category" )
);
session.setAttribute( "editor", editor );
[/code]
2. I have this EditorBean class. This EditorBean is a
business bean. I am struggling with how the EditorBean
pass the data in between the controller and the
database.
[code]
import org.apache.artimus.logon.dao.*;
public class EditorBean 
{   
   private String username;
   private String userrole;
   private String category;
   EditorDAO ed = new MySQLEditorDAO();
   public EditorBean() {}
   public EditorBean( String username, String
userrole, String category )
   {
      setUsername( username );
      setUserrole( userrole );
      setCategory( category );
   }
   public String getUsername(){ return username; }
   public void setUsername( String username ) {
this.username = username; }
   public String getUserrole(){ return userrole; }
   public void setUserrole( String userrole ) {
this.userrole = userrole; }
   public String getcategory(){ return category; }
   public void setCategory( String category ) {
this.category = category; }
   // the parameters in the method below have problems
   public EditorBean findEditorData( String username,
EditorBean editorData )
   {
      // What do I do here?
      ed.findEditor( String username, ?????? );
      // I am not sure what to return here
      return ?????;
   }
}
[/code]
3. Here is my data access class:
[code]
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import
org.apache.artimus.logon.exceptions.EditorDAOSysException;
import org.apache.artimus.ConnectionPool.DBConnection;

public class MySQLEditorDAO implements EditorDAO{
   // the parameters of the method below have problems
   public EditorBean findEditor( String username,
?????? )
        throws EditorDAOSysException
   {
      Connection conn = null;
      Statement stmt = null;
      ResultSet rs = null;
      try
      {
         conn = DBConnection.getDBConnection();
         stmt = conn.createStatement();
         String query = "SELECT user_role,
journal_category FROM members WHERE user_name = '" +
username + "'";
         rs = stmt.executeQuery( query );
         if (rs.next())
         {
            // something is wrong in returning the
information about that editor
            return new EditorBean( username,
rs.getString( "user_role" ), rs.getString(
"journal_category") );
         }
         else
         {
            System.out.println( "invalid user name" );
            return null;
         }
      }
      catch (SQLException se)
      {
         throw new
EditorDAOSysException("SQLException: " +
se.getMessage());
      }
      finally
      {
         if ( conn != null )
         {
            try
            {
               rs.close();
               rs = null;
               stmt.close();
               stmt = null;
               conn.close();
            }
            catch( SQLException sqlEx )
            {
               System.out.println( "Problem occurs
while closing " + sqlEx );
            }
            conn = null;
         }
      }
   }
}
[/code]


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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

Reply via email to