JDBC: Closing Connection does it close statement and resultset


General J2EE: JDBC: Closing Connection does it close statement and resultset

  1. In my application I am facing ORA-0100 Maximum open cursors exceeded problem. We are executing quite a few queries and stored procedures before we close the connection object. But in few places statements and resultsets are not closed. Can these be a problem? Shouldn't they be automatically closed when the connection is closed? We are executing this block of code in a loop.
  2. I think Oracle has had problems previously with keeping the cursors open even after closing the connection. You can try to close the ResultSet and Statement excplicitly, but you could also try changing the JDBC driver version (not sure what you're running and what you should switch to though). In general, closing the Connection should automatically close any Statements and ResultSets associated with that Connection. Cheers, Fredrik
  3. using the following version of oracle driver:- Specification-Title: "Oracle JDBC driver classes for use with JDK1.2 and JDK1.3" Specification-Version: "Oracle JDBC Driver version -" Specification-Vendor: "Oracle Corporation" . Implementation-Title: "classes12 archives" Implementation-Version: "Oracle JDBC Driver version -" Implementation-Vendor: "Oracle Corporation" Implementation-Time: "Thu Apr 25 23:06:00 2002" There are only few places we found the resultset and statement not being closed. The block of code we are running in a loop makes many calls to database using different methods. Each time we pass the connection object and close the connection at the end of the iteration. We get a new connection for the next iteration. Ideally it should have closed all the objects but it does not.
  4. Hello Techies, I am new to this forum. I have a Jsp which submit the form using on 'onclick' event. It is working fine with Mozilla but it is creating problem with Internet Explorer. Means at the server side, normally the server creates one thread for a request. But it creates two threads for the same request at a time using InternetExplorer. Can u plz suggest me how to resolve this. Thanks Javed
  5. Off topic, but I'll try to help.[ Go to top ]

    Had a similar issue myself last week, and it turned out to be quite simple. If the 'onclick' handler is associated with the submit button (Usually to do some pre-submission processing of the form fields) and the handler calls 'form.submit()', this will cause the second submission (In addition to the one automatically generated by the submit button itself). Either drop the 'form.submit()' from the handler, or make the handler return 'false', so that the default behaviour of the button isn't carried out. Hope this makes sense. Bob
  6. You may exhaust Oracle's configured max open cursors when using a connection pool. It this case you must make sure Oracle's max open cursors are <= to the max connections in your pool. However, you should close statements (and ResultSets) when returing the connection to the pool (happens upon closing the connection).
  7. According to the API docs, closing a Statement results in the closure of any associated ResultsSets. It's not quite as specific when it comes to Connection.close() - simply referring to 'Releasing JDBC resources'. The sensible route would be to always close Statements and ResultSets when you're done with them - after all, behaviour may vary from one implementation (i.e. driver) to another. In the long term, save yourself the bother or writing all that repetitive try/catch/finally/if(x!=null){x.close()} stuff by looking at the functionality offered by JdbcTemplate, as provided by the Spring Framework. This does all the tedious opening closing for you (and a lot more besides). http://www.springframework.org/docs/api/org/springframework/jdbc/core/JdbcTemplate.html
  8. P.S. The whole subject is complicated further when dealing with connection pools as calling Connection.close() simply returns the connection to the pool with really closing it(As far as I understand things) - who knows whether this leads to the (assumed) clean-up behaviour that is normally triggered by a call to close()!
  9. As an alternative to Spring's JdbcTemplate (if you're not using Spring's other useful features), you may also have a look at Jakarta Commons DBUtils, which offers a clean and easy way to use JDBC.
  10. Thank you everyone for replying. Closing all the statements and resultset has solved the problem. Although closing connection ideally should have taken care but I guess it does not. Thanks once again......