KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > dbtags > connection > CloseConnectionTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.dbtags.connection;
18
19 import java.sql.Connection JavaDoc;
20 import java.sql.SQLException JavaDoc;
21
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 /**
25  * <p>JSP tag closeconnection, used to close the
26  * specified java.sql.Connection.<p>
27  *
28  * <p>JSP Tag Lib Descriptor
29  * <pre>
30  * &lt;name>closeConnection&lt;/name>
31  * &lt;tagclass>org.apache.taglibs.dbtags.connection.CloseConnectionTag&lt;/tagclass>
32  * &lt;bodycontent>empty&lt;/bodycontent>
33  * &lt;info>Close the specified connection. The "conn" attribute is the name of a
34  * connection object in the page context.&lt;/info>
35  * &lt;attribute>
36  * &lt;name>conn&lt;/name>
37  * &lt;required>true&lt;/required>
38  * &lt;rtexprvalue>false&lt;/rtexprvalue>
39  * &lt;/attribute>
40  * </pre>
41  *
42  * @author Morgan Delagrange
43  * @see ConnectionTag
44  */

45 public class CloseConnectionTag extends TagSupport JavaDoc {
46   
47   private String JavaDoc _connId = null;
48
49   /**
50    * The "conn" attribute is the name of a
51    * page context object containing a
52    * java.sql.Connection.
53    *
54    * @param connectionId
55    * attribute name of the java.sql.Connection to close.
56    * @see ConnectionTag
57    */

58   public void setConn(String JavaDoc connectionId) {
59     _connId = connectionId;
60   }
61   
62   public int doStartTag() {
63
64     try {
65       Connection JavaDoc conn = (Connection JavaDoc)pageContext.getAttribute(_connId);
66       conn.close();
67       conn = null;
68     } catch (SQLException JavaDoc e) {
69       // failing to close a connection is not fatal
70
e.printStackTrace();
71     }
72     
73     return EVAL_BODY_INCLUDE;
74   }
75
76   public void release() {
77     _connId = null;
78   }
79     
80 }
81
Popular Tags