KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > database > statement > SimplePreparedStatement


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

21
22 package org.dbunit.database.statement;
23
24 import org.dbunit.dataset.ITable;
25 import org.dbunit.dataset.datatype.DataType;
26 import org.dbunit.dataset.datatype.TypeCastException;
27
28 import java.sql.Connection JavaDoc;
29 import java.sql.SQLException JavaDoc;
30
31 /**
32  * @author Manuel Laflamme
33  * @version $Revision: 1.14 $
34  * @since Mar 16, 2002
35  */

36 public class SimplePreparedStatement extends AbstractPreparedBatchStatement
37 {
38     private int _index;
39     private int _result;
40
41     public SimplePreparedStatement(String JavaDoc sql, Connection JavaDoc connection)
42             throws SQLException JavaDoc
43     {
44         super(sql, connection);
45         _index = 0;
46         _result = 0;
47     }
48
49     ////////////////////////////////////////////////////////////////////////////
50
// IPreparedBatchStatement interface
51

52     public void addValue(Object JavaDoc value, DataType dataType)
53             throws TypeCastException, SQLException JavaDoc
54     {
55         // Special NULL handling
56
if (value == null || value == ITable.NO_VALUE)
57         {
58             _statement.setNull(++_index, dataType.getSqlType());
59             return;
60         }
61
62         dataType.setSqlValue(value, ++_index, _statement);
63     }
64
65     public void addBatch() throws SQLException JavaDoc
66     {
67         boolean result = _statement.execute();
68         if (!result)
69         {
70             _result += _statement.getUpdateCount();
71         }
72         _index = 0;
73 // _statement.clearParameters();
74
}
75
76     public int executeBatch() throws SQLException JavaDoc
77     {
78         int result = _result;
79         clearBatch();
80         return result;
81     }
82
83     public void clearBatch() throws SQLException JavaDoc
84     {
85 // _statement.clearParameters();
86
_index = 0;
87         _result = 0;
88     }
89
90 }
91
92
93
94
95
96
97
Popular Tags