Author: fbysssBlog: blog.9cbs.net/fbysss Disclaimer: This article from the original fbysss, reproduced or quoted, please indicate the reference address.
Question: Write a getResultset method in dbmanager.java, which is not to release the connection every time you go. However, in different operating system environments, it is not necessarily good, for example, under Windows, the ResultSet is able to leave the connection, but there is no line under Linux. If you want to modify all pages for Collection to make changes, the amount of change is imagined, this is me and it is unwilling to see. How to do? Fortunately, I found CachedRowSet. It saved me. The best is that cachedrowset inherits from the ResultSet, I only need to modify the core method, the page does not have to change! Code: / ** * Get * @Return ResultSet * / / // public resultset getResultset (String _ssql) throws exception {public resultset getResultSet (String_ssql) throws exception {
System.out.println ("----- Return Data Set ------- Rowset1.0"); connection vconn = getConnection (); try {/ * preparedState pstMt = vconn.preparestatement (_ssql, ResultSet.Type_Scroll_Sensitive, ResultSet.concur_read_only); ResultSet RS = PSTMT.executeQuery (); * / cachedrowset crs = new cachedrowsetImpl ();
Crs.SETURL (SURL); crs.setUsername (SUSERNAME); Crs.SetPassword (spassword); crs.setcommand; crs.execute (vconn); return crrs; / * crs.release (); crs.populate RS); RETURN CRS;} * /} catch ("EXCEPTION EX) {throw new Exception (" gets the cachedrowset error.: " EX.TOSTRING () " / n SQL: " _ssql);} finally {freeConnection Vconn);}}