On Tue, May 15, 2001 at 01:23:13PM -0700, <enter name here> wrote:
> Toby -
>
> Well, I have a class with static utility methods such as:
>
> public static void closeConnection(Connection connection)
> public static void closeStatement(Statement statement)
> public static void closeResultSet(ResultSet resultset)
>
> which, back in the day had a little more utility for getting pooled
> connections for non-bean stuff - I just kept the close calls because it
> keeps me from having try/catch blocks in my finally blocks...
>
> anyway, my beans use JNDI to get the pooled connections now and I was
> continuing to use these static calls, but received rmi errors ( a la
> java.rmi.ServerException: Transaction
> rolledback:com/bebee/recommender/utility/DatabaseUtility ).
Please, provide details here. *Exactly* where did you receive this exception?
What was the stacktrace? What code is in those static methods?
> So I removed the calls to these static methods and replaced them with
> Connection.close(), etc calls. This stopped the rmi errors. My conclusion
> here was that an ejb calling static methods is apparently a bad thing (makes
> sense since it is trying to circumvent the container, i guess?)
There is no problem with calling static methods in utility classes from
an EJB.
> The next problem was that since I was used to using my utility methods
> (which checked for nulls being passed in) I grew lazy and closed things in
> no particular order which resulted in NullPointerExceptions when I did the
> following:
>
> conn.close();
> preparedstmt.close(); // null pointer here
> // interesting point to make here -- no errors on regular statements
> closed here, just prepared ones... seemes rather odd ( i would be interested
> to hear more about this)
> rs.close();
Ah, yes, this will give you problems because the statements and result sets
need to have references to the connection on which they were created. You
shouldn't get an exception, though, it should just be ignored.
If you post the stacktraces then we can look into what's causing the NPE.
> According to colleagues the 'proper' order for closing this stuff is
> ResultSet then Statement then Connection - so I will take them at their
> word.
Yes, it makes a lot more sense to close them in that order, but the pooled
connections shouldn't be so fragile.
> So in conclusion, I confiused the hell out of myself -- which is good every
> now and again.
Well, only if you get some understanding to replace the confusion.
Toby.
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user