01: /*
02: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.mandarax.jdbc.server;
19:
20: import java.sql.*;
21: import java.sql.ResultSet;
22: import org.mandarax.jdbc.server.sql.SelectStatement;
23: import org.mandarax.kernel.*;
24:
25: /**
26: * PreparedStatement implementation.
27: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
28: * @version 3.3.2 <29 December 2004>
29: * @since 3.0
30: */
31: class PreparedStatementImpl extends StatementImpl implements
32: java.sql.PreparedStatement {
33:
34: private String sql = null;
35: private SelectStatement select = null;
36: private static LogicFactory lfactory = LogicFactory
37: .getDefaultFactory();
38:
39: /**
40: * Constructor.
41: * @param connection the connection used
42: * @param kb a knowledge base
43: * @param sql the sql statement
44: */
45: PreparedStatementImpl(Connection connection, KnowledgeBase kb,
46: String sql) throws SQLException {
47: super (connection, kb);
48: this .sql = sql;
49: this .select = parse(sql);
50: select.prepare();
51: select.setKB(kb);
52: }
53:
54: /**
55: * Execute the query.
56: * @return a result set
57: */
58: public ResultSet executeQuery() throws SQLException {
59: select.checkBindings();
60: return executeQuery(select, sql);
61: }
62:
63: /**Generated method stub. This method is not supported by the mandarax jdbc driver.
64: * @see java.sql.PreparedStatement#clearParameters()
65: */
66: public void clearParameters() throws SQLException {
67: select.resetAll();
68:
69: }
70:
71: /**
72: * Executes the statement, which may return multiple results.
73: */
74: public boolean execute() throws SQLException {
75: select.checkBindings();
76: nextResultSet = executeQuery(select, sql);
77: return nextResultSet != null;
78: }
79:
80: /**
81: * Set the object on a certain index.
82: * @param parameterIndex the index
83: * @param x the object
84: */
85: public void setObject(int parameterIndex, Object x)
86: throws SQLException {
87: select.bind(parameterIndex, x);
88: }
89: }
|