[opencms-dev] nested SQL Exception if connection pool

Jordi Martí jmarti at theinit.com
Fri Feb 29 17:48:31 CET 2008


Wops, my bad:

Connection c;
Statement st;
ResultSet rs;
 try {
 	c=getSqlManager()......;
	st=c......
 	rs=st....
 	}
 catch (Exception e) {
 	e.printStackTrace();
 	}
 finally {
 	rs.close();
	st.close();
 	c.close();
 	}

(this is an ugly example, you should do some exception checking, some
logging, create managers and dao classes to do all this stuff, blablablabla,
ok?).

  
 
JORDI MARTÍ 
Skype id: jmarti.theinit
 
 

-----Mensaje original-----
De: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org]
En nombre de Christoph P. Kukulies
Enviado el: viernes, 29 de febrero de 2008 17:31
Para: The OpenCms mailing list
Asunto: Re: [opencms-dev] nested SQL Exception if connection pool

On Fri, Feb 29, 2008 at 04:46:00PM +0100, Jordi Mart? wrote:
> Do you free statements and close connections?
> 
> try {
> 	Connection c=getSqlManager()......;
> 	ResultSet rs=c....
> 	}
> catch (Exception e) {
> 	e.printStackTrace();
> 	}
> finally {
> 	rs.close();
> 	c.close();
> 	}

I'm getting 
An error occurred at line: 88 in the jsp file:
/WEB-INF/jsp/offline/system/modules/org.yaml.frontend/templates/yamlmain.jsp
rs cannot be resolved
85: e.printStackTrace();
86: }
87: finally {
88: rs.close();
89: c.close();
90: }
91: %>

An error occurred at line: 89 in the jsp file:
/WEB-INF/jsp/offline/system/modules/org.yaml.frontend/templates/yamlmain.jsp
c cannot be resolved
86: }
87: finally {
88: rs.close();
89: c.close();
90: }
91: %>
92: </div>


Here is my template code:

<%@page import="org.opencms.jsp.*,org.opencms.file.*,java.util.*,java.sql.*"
%>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
       
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<cms:template element="head" >
<cms:include file="../elements/yamlhead" element="head"/>
</cms:template>
      <div id="main">
        <div id="col1">
          <div id="col1_content" class="clearfix">
            <!-- add your content here -->
<%
         CmsJspActionElement jsp = new CmsJspActionElement(pageContext,
request,response);

         String konto=request.getParameter("konto");
         String tmp,item,desc,id;
          
         try { 
             java.sql.Connection c =
 
org.opencms.main.OpenCms.getSqlManager().getConnection("application");
            java.sql.Statement st = c.createStatement();
           java.sql.ResultSet rs = st.executeQuery("select id,name from
konten");
            java.sql.ResultSetMetaData md = rs.getMetaData();
            out.println("\n<ul>");
            while(rs.next()) {
                out.println("\n<li>");
                for(int i=1; i<= md.getColumnCount(); i++) {
                  item=rs.getString(i);
                  tmp = "<a
href=\"/opencms/opencms/sites/kuku/index.html?konto=" +item + "\" >"+
item + "</a>";

                  if(tmp == null)
                      tmp=" ";
                  out.println(  tmp );
                }
            out.println("</li>");
           }
            out.println("</ul>");

%>

          </div>
        </div>
        <div id="col2">
          <div id="col2_content" class="clearfix">
            <!-- add your content here -->



          </div>
        </div>
        <div id="col3">
          <div id="col3_content" class="clearfix">
            <!-- add your content here -->
<%
      
      if(( id=request.getParameter("konto"))!=null){
           rs = st.executeQuery("select * from buchung where
konto="+id);
          ;
          out.println("\n<ul>");
          md = rs.getMetaData();
          while(rs.next()) {
                out.println("\n<li>");
                for(int i=1; i<= md.getColumnCount(); i++) {
                  item=rs.getString(i);
                  
                  tmp =  item ;
               if(tmp == null)
                      tmp=" ";
                  out.println(  tmp );
                }
            out.println("</li>");
          }
         
          out.println("</ul>");
        } else { out.println("<h2>Set empty</h2>"); }
        } catch (Exception e) {
               e.printStackTrace();
         }
finally  {
      rs.close();
      c.close();
}
%>
          </div>
          <!-- IE Column Clearing -->
          <div id="ie_clearing">   </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

> 
>    
>  
> JORDI MARTÍ 
> Email: jmarti at theinit.com
> Tlfno: 944.01.50.40 - Fax: 944.153.424
> Móvil: 605.41.82.93
> Skype ID: jmarti.theinit
>  
>  
>  
>  
>  
>  
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de

_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev




More information about the opencms-dev mailing list