tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ayhan Peker <ay...@image-data.com>
Subject RE: what is wrong with this bean/is this a valid bean?
Date Thu, 01 May 2003 14:34:42 GMT
Thank you very much for the answers..

I have checked the links..It sounds wonderful but there is a problem:
I can not find the class RowSetDynaClass in bin distributions.

I tried every package..But it is not there..

Ayhan


At 12:06 30/04/03 -0500, you wrote:
>Ayhan,
>
>I posted about this same problem yesterday. The problem is that when you 
>close the database connection, you also close the resultSet. (You can use 
>resultSets to update the database and therefore the connection must remain 
>open.) So, you have a few options. One, you can move conn.close() to the 
>end of the page. Or, a better option, as Yoav Shapira and Andrew Geery 
>pointed out to me is:
>
>-----------
>Don't send ResultSets around.  Instead, have the servlets loop through
>the result set and create whatever object you need to hold the result
>set's contents.  Then close and discard the result set (and statement,
>and connection to the db, etc, all in a finally {} block or whatever to
>ensure they execute blah blah blah).
>
>Instead of passing the resultset, pass this object.  You have more
>control over its implementation, whether it's serializable, etc.  As you
>noticed, the ResultSet interface is subject to different implementations
>in different JDBC drivers (even drivers from the same vendor for the
>same DB on different platforms).  This makes the ResultSet object a bad
>candidate for a session attribute, because variable platform-dependent
>behavior tends to occur.
>
>Yoav Shapira
>Millennium ChemInformatics
>-----------
>
>An easy way to do this "automagically" done for you is to use
>org.apache.commons.beanutils.RowSetDynaClass
>
>See the RowSetDynaClass JavaDoc API at
>http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/RowSetDynaClass.html
>which also explains exactly how to use it.
>
>Note that you will need to download the beanutils package, extract the
>beanutils jar and put it where your application can find it. You can get
>the package from
>http://jakarta.apache.org/commons/beanutils/
>
>[The commons-beanutils.jar is included as part of Tomcat in the
>$CATALINA_HOME/server/lib directory, but due to the way the classloaders
>work, your application won't be able to see it. If you want to just use
>this jar, you'll need to copy it to a location where your application
>can see it.]
>
>hth
>Andrew
>---------------------
>
>Also, you should search the list before posting questions - after all, 
>this came up yesterday. :-)
>
>Steve
>
>
> >-----Original Message-----
> >From: Ayhan Peker [mailto:ayhan@image-data.com]
> >Sent: Wednesday, April 30, 2003 12:01 PM
> >To: tomcat-user@jakarta.apache.org
> >Subject: what is wrong with this bean/is this a valid bean?
> >
> >
> >hi..
> >I have a bean, which is a global bean.
> >here it is:
> >
> >
> >
> >package genericbeans;
> >
> >/**
> >  *  Description of the Class
> >  *
> >  *@author     Administrator
> >  *@created    30 April 2003
> >  */
> >public class GenericSQLBean {
> >       private java.sql.ResultSet resultset = null;
> >
> >
> >       /**
> >       *  Description of the Method
> >       *
> >       *@param  query  Description of the Parameter
> >       *@param  con    Description of the Parameter
> >       */
> >       public void setResultset(String query,
> >java.sql.Connection con) {
> >               java.sql.Statement stmt = null;
> >               try {
> >                       stmt = con.createStatement();
> >                       this.resultset = stmt.executeQuery(query);
> >                       System.out.println(query);
> >               } catch (java.sql.SQLException e) {
> >                       e.printStackTrace();
> >               } finally {
> >                       try {
> >                               if (stmt != null) {
> >                                       stmt.close();
> >                               }
> >                       } catch (java.sql.SQLException ignore) {}
> >               }
> >       }
> >
> >
> >       /**
> >       *  Gets the results attribute of the GenericSQLBean object
> >       *
> >       *@return    The results value
> >       */
> >       public java.sql.ResultSet getResultset() {
> >               return this.resultset;
> >       }
> >
> >}
> >
> >when i try to use this from a jsp page like:
> >
> >  String query="select count(*) from pix";
> >
> >
> >              genericbeans.GenericSQLBean
> >sqlbean=(genericbeans.GenericSQLBean)ctx.lookup(
> >                  "java:comp/env/genericbeans/GenericSQLBean");
> >
> >               sqlbean.setResultset(query,  conn);
> >              ResultSet rst=sqlbean.getResultset();
> >
> >               conn.close();
> >              // Statement stmt = conn.createStatement();
> >              // ResultSet rst =
> >              // stmt.executeQuery();
> >              if(rst.next()) {
> >                  System.out.println(rst.getInt(1));
> >
> >              }
> >
> >
> >it is giving
> >
> >
> >
> >Connection is closed.  Operation is not permitted.
> >         at
> >org.postgresql.jdbc1.AbstractJdbc1ResultSet.next(AbstractJdbc1R
> >esultSet.java:63)
> >         at
> >org.apache.commons.dbcp.DelegatingResultSet.next(DelegatingResu
> >ltSet.java:135)
> >         at org.apache.jsp.index_jsp._jspService(index_jsp.java:81)
> >         at
> >org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
> >         at
> >javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> >         at
> >org.apache.jasper.servlet.JspServletWrapper.service(JspServletW
> >rapper.java:204)
> >
> >
> >
> >please help me .. why am i receiving this error.
> >
> >This bean will take query string  and a connection, will
> >perform the query
> >and will return a results set.
> >
> >when i get the result set and do something with thi sresult set
> >/////
> >
> >if(rst.next()) {
> >                  System.out.println(rst.getInt(1));
> >
> >              }
> >
> >
> >I am receiving that error
> >
> >any ideas
> >
> >ayhan
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message