Subject | Re: ResultSet closing |
---|---|
Author | nrajagopal35 |
Post date | 2003-12-05T05:36:58Z |
Thanks for your suggestion and update
Thanks & Regards,
Rajagopal N
--- In Firebird-Java@yahoogroups.com, "Robert DiFalco" <rdifalco@t...>
wrote:
Thanks & Regards,
Rajagopal N
--- In Firebird-Java@yahoogroups.com, "Robert DiFalco" <rdifalco@t...>
wrote:
> Rajagopal,
>
> I would encourage you to not close the result set a second time just to
> make sure. "Just in case" programming usually indicates that you may not
> be in control of your program flow, better to do things intentionally.
>
> Most resources, files, result sets, etc. will complain if you try to
> close them more than once. The code is being very explicit, it is saying
> that you have lost control of your code and are unnecessarily closing
> the resource after it has already been closed. If you put the first
> close in a finally block, you will not require the second "just in case"
> close.
>
> Just a suggestion,
>
> R.
>
> -----Original Message-----
> From: nrajagopal35 [mailto:nrajagopal35@y...]
> Sent: Thursday, December 04, 2003 9:10 PM
> To: Firebird-Java@yahoogroups.com
> Subject: [Firebird-Java] Re: ResultSet closing
>
>
> Thanks for your update. The problem doesn't occur if I follow the
> pattern you have described.
>
> In some of my code, the ResultSet is closed in the finally block for
> the second time to make sure that ResultSet is closed, then in that
> case I am getting the Exception, may be I have to catch the Exception
> and do nothing with that in these scenarios.
>
> Thanks & Regards,
> Rajagopal N
>
> --- In Firebird-Java@yahoogroups.com, "Robert DiFalco" <rdifalco@t...>
> wrote:
> > Well, it's fairly straight-forward, you tried to close the result set
> > when it was already closed. Why not try this?
> >
> > void doStuff( Connection con ) throws SQLException
> > {
> > PreparedStatement statement = con.prepareStatement( ... );
> >
> > try
> > {
> > ...
> >
> > ResultSet rset = statement.executeQuery();
> >
> > try
> > {
> > ...
> > }
> > finally
> > {
> > rset.close();
> > }
> > }
> > finally
> > {
> > statement.close();
> > }
> > }
> >
> > try
> > {
> > doStuff( con );
> > con.commit();
> > }
> > catch ( SQLException e )
> > {
> > try { con.rollback(); } catch ( Exception e } {}
> > }
> >
> > You can use this basic pattern for updates or queries.
> >
> >
> >
> > -----Original Message-----
> > From: nrajagopal35 [mailto:nrajagopal35@y...]
> > Sent: Thursday, December 04, 2003 8:55 PM
> > To: Firebird-Java@yahoogroups.com
> > Subject: [Firebird-Java] ResultSet closing
> >
> >
> > Dear Team,
> >
> > Does any one knows why JayBird throws "java.sql.SQLException: The
> > resultSet is closed", when the ResultSet is already closed.
> >
> > According to specifications, if you close the statement then the
> > ResultSet also is closed.
> >
> > In our code to make sure the closing of ResultSet and Statement, we
> > will close the ResultSet after closing Statement. In some cases to
> > ensure the closing, the same were closed in finally block for the
> > second time.
> >
> > In these situations, SQLException is thrown with resultSet is closed.
> >
> > Say in a block of code we are closing statement and again closing the
> > ResultSet in the try block. We catch SQLException and assume that
> > there is some problem in executing the query and do rollback. In these
> > cases SQLException thrown for ResultSet closed will be a problem.
> >
> > So instead of throwing an SQLException just we will simply return
> > without throwing any Exception or at the
> > most we can log the message. Because SQLException can be thrown only
> > when some real problem occurs.
> >
> > Kindly update me if anyone knows the reason behind this.
> >
> > Thanks & Regards,
> > Rajagopal N
> >
> >
> > Yahoo! Groups Sponsor
> > ADVERTISEMENT
> >
> >
> >
> >
> > To unsubscribe from this group, send an email to:
> > Firebird-Java-unsubscribe@yahoogroups.com
> >
> >
> >
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
>
> Yahoo! Groups Sponsor
>
>
>
> To unsubscribe from this group, send an email to:
> Firebird-Java-unsubscribe@yahoogroups.com
>
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.