KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > dbtags > statement > ExecuteTag


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 package org.apache.taglibs.dbtags.statement;
17
18 import java.sql.SQLException JavaDoc;
19
20 import javax.servlet.jsp.JspTagException JavaDoc;
21 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
22
23 /**
24  * <p>JSP tag execute, executes the query for the enclosing statement or
25  * preparedstatement tag.
26  
27  * <p>Setting the "ignoreErrors" atttibute to true
28  * will instruct the page to continue in the event of a SQLException,
29  * otherwise by default exceptions will throw a JspTagException.</p>
30  *
31  * <p>JSP Tag Lib Descriptor
32  * <pre>
33  * &lt;name>execute&lt;/name>
34  * &lt;tagclass>org.apache.taglibs.dbtags.statement.ExecuteTag&lt;/tagclass>
35  * &lt;bodycontent>JSP&lt;/bodycontent>
36  * &lt;info>Executes the query for the enclosing statement or
37  * preparedstatement tag.&lt;/info>
38  * &lt;attribute>
39  * &lt;name>ignoreErrors&lt;/name>
40  * &lt;required>false&lt;/required>
41  * &lt;rtexprvalue>true&lt;/rtexprvalue>
42  * &lt;/attribute>
43  * </pre>
44  *
45  * @author Morgan Delagrange
46  * @see StatementImplTag
47  * @see QueryTag
48  * @see org.apache.taglibs.dbtags.preparedstatement.PreparedStatementImplTag
49  */

50 public class ExecuteTag extends BodyTagSupport JavaDoc{
51   
52   boolean _ignoreErrors = false;
53
54   public void setIgnoreErrors(boolean ignoreErrors) {
55     _ignoreErrors = ignoreErrors;
56   }
57
58   public int doEndTag() throws JspTagException JavaDoc {
59     try {
60       StatementTag stmtTag =
61         (StatementTag) findAncestorWithClass(this, Class.forName("org.apache.taglibs.dbtags.statement.StatementTag"));
62       stmtTag.executeUpdate();
63     } catch (ClassNotFoundException JavaDoc e) {
64       throw new JspTagException JavaDoc(e.toString());
65     } catch (SQLException JavaDoc e) {
66       if (_ignoreErrors == false) {
67         throw new JspTagException JavaDoc(e.toString());
68       } else {
69         // print out error rather than throw a fatal exception
70
e.printStackTrace();
71       }
72     }
73     
74     return EVAL_PAGE;
75   }
76   
77   public void release(){
78     _ignoreErrors = false;
79   }
80
81 }
82
Popular Tags