Title: RE: [JBoss-user] Please help me ...

I agree with the Fred that the SLSB is the better route and cleaner overall.  In any event, you are only going to return an int.  So, in your remote interface add a public int getXYZ() ... and then add the same to the Bean.  The following is from a SLSB but the same would work in a Entity Bean.  Note: we put the name of our datasource into an <env-entry> rather than hard code; you wouldn't need to do this. 

John


Remote Interface
    public abstract int countByXYZ( int arg ) throws RemoteException, ... ;


Implementation Class
    public int countByXYZ( int arg) throws RemoteException, ... {
        DataSource              ds = null;
        Connection               con = null;
        PreparedStatement ps = null;
        ResultSet result = null;
        int count = 0;
        final  String query = "select count(0) from DUMMY_TBL  where ARG_TO_MATCH = ?  ";

        try {
            InitialContext context = new InitialContext();
            String  dataSourceName = (String)context.lookup("java:comp/env/data_source_name");
            ds = (DataSource)context.lookup("java:" + dataSourceName);
            con = ds.getConnection();
            con.setAutoCommit(false);
            ps  = con.prepareStatement(query);
            ps.setInt( 1, arg );
            result = ps.executeQuery();
            if (result.next()) {
                count = result.getInt(1);
            }
        }
        catch( Exception e ) {
            throw new BusinessException( e );
        }
        finally {
            try { result.close(); } catch( Exception e ) { }
            try { ps.close(); } catch( Exception e ) { }
            try { con.close(); } catch( Exception e ) { }
        }
        return count;
    }

-----Original Message-----
From: IvanLatysh [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 24, 2001 8:58 AM
To: John Moore; [EMAIL PROTECTED]
Subject: Re: [JBoss-user] Please help me ...


Hello, John!
You wrote to "'IvanLatysh'" <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> on Wed, 24
Oct 2001 08:46:42 -0700:


 JM> or,  #4) Rather than a new entity bean, use the existing entity bean
 JM> and put a new method that grabs the datasource from jndi, gets a
 JM> connection, runs the query and closes (hands back) the connection.
This way sounds nice.
But how to return data from my method? Or just return a Vector?

 JM> I have done #2 & #4, more often #2.

 JM> #1 won't buy you anything except more beans to manage.
 JM> #3 is a waste of system resources

 JM> I see any ways how to do it.
 JM> 1. Build the new EntityBean which will execute SQL and will
 JM> represent summary information (but I see something wrong here)
 JM> 2. Build a SessionStateless bean and execute SQL to get this summary
 JM> information
 JM> 3. Build SessionStateless bean to get data from my EntityBean-s and
 JM> group this data manualy.

 JM> My question - how to have it done more easely and in right way.

---
Yours sincerely, Ivan Latysh.
[EMAIL PROTECTED]
http://ivan.yourmail.com

Reply via email to