KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > execute > SQLExecutionResult


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.sql.execute;
21
22 import java.sql.ResultSet JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.sql.Statement JavaDoc;
25
26 /**
27  * Encapsulates the result of the execution of a single SQL statement.
28  *
29  * @author Andrei Badea
30  */

31 public class SQLExecutionResult {
32
33     /**
34      * The info about the executed statement.
35      */

36     private final StatementInfo statementInfo;
37     
38     /**
39      * The executed statement.
40      */

41     private final Statement JavaDoc statement;
42
43     /**
44      * The ResultSet returned by the statement execution.
45      */

46     private final ResultSet JavaDoc resultSet;
47
48     /**
49      * The exception (if any) which occurred while executing the statement.
50      */

51     private final SQLException JavaDoc exception;
52     
53     /**
54      * The execution time in milliseconds.
55      */

56     private final long executionTime;
57     
58     /**
59      * The number of the rows affected by the statement execution.
60      */

61     private final int rowCount;
62     
63     public SQLExecutionResult(StatementInfo info, Statement JavaDoc statement, ResultSet JavaDoc resultSet, long executionTime) {
64         this(info, statement, resultSet, -1, null, executionTime);
65     }
66     
67     public SQLExecutionResult(StatementInfo info, Statement JavaDoc statement, int rowCount, long executionTime) {
68         this(info, statement, null, rowCount, null, executionTime);
69     }
70     
71     public SQLExecutionResult(StatementInfo info, Statement JavaDoc statement, SQLException JavaDoc exception) {
72         this(info, statement, null, -1, exception, 0);
73     }
74     
75     private SQLExecutionResult(StatementInfo info, Statement JavaDoc statement, ResultSet JavaDoc resultSet, int rowCount, SQLException JavaDoc exception, long executionTime) {
76         this.statementInfo = info;
77         this.statement = statement;
78         this.resultSet = resultSet;
79         this.rowCount = rowCount;
80         this.exception = exception;
81         this.executionTime = executionTime;
82     }
83     
84     public StatementInfo getStatementInfo() {
85         return statementInfo;
86     }
87     
88     public ResultSet JavaDoc getResultSet() {
89         return resultSet;
90     }
91     
92     public int getRowCount() {
93         return rowCount;
94     }
95     
96     public SQLException JavaDoc getException() {
97         return exception;
98     }
99     
100     public long getExecutionTime() {
101         return executionTime;
102     }
103     
104     public void close() throws SQLException JavaDoc {
105         try {
106             if (resultSet != null) {
107                 resultSet.close();
108             }
109         } finally {
110             if (statement != null) {
111                 statement.close();
112             }
113         }
114     }
115     
116     public String JavaDoc toString() {
117         return "SQLExecutionResult[resultSet=" + resultSet + ",rowCount=" + rowCount + ",exception=" + exception + ",executionTime=" + executionTime + "]";
118     }
119 }
120
Popular Tags