I am using jboss server and Using BMP and I have the following method in my
ElementEntityBean bean:
Here the method returns an integer and surely I cant put this in the Home
interface ,but if I put this in the Remote
Interface I should use the create statement in the Client like which it
creates a database record which I dont need.
My QUESTION IS where should I have this method :::::
ElementEntityHome expHome = (ElementEntityHome)
getHome("im30/ElementEntity",ElementEntityHome.class);
ElementEntity eleEntity =expHome.create();
int i= eleEntity.questionsAskedFromUser(userId);


!!ELEMENTENTITYBEAN!!
/**
    *  Get the Number of Questions asked from a User.
    */
    public int questionsAskedFromUser(String userID)
        throws RemoteException
    {
     PreparedStatement pstmt = null;
        Connection conn = null;
        byte type=1;  file://Question type
  try
  {
      System.out.println("questionsAskedFromUser(String userID) Called");

      /*
       * Acquire DB connection
       */
            DBConnectionHome hom = (DBConnectionHome)
getHome("java:comp/env/ejb/DBConnection");
            DBConnection DBCon = hom.create();
            conn = DBCon.getConnection();

      /*
       * Find the Entity in the DB
       */
      pstmt = conn.prepareStatement("select count(*) from element WHERE
type= ? AND userID= ? ");
            pstmt.setByte(1,type);
            pstmt.setString(2,userID);
      ResultSet rs = pstmt.executeQuery();

      /*
       * No errors occurred, so return the Primary Key
       */
            if (rs.next())
          return rs.getInt(1);
            else
                throw new RemoteException("Count is 0");
        }
     catch (Exception e)
  {
         throw new RemoteException("Exception: " + e.toString());
     }
     finally
  {
      /*
       * Release DB Connection for other beans
       */
      try
   {
       pstmt.close();
      }
      catch (Exception e) { }
      try
   {
       conn.close();
      }
      catch (Exception e) { }
     }
    }




_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to