| 1 | /* Statement.java -- Interface for executing SQL statements.
|
|---|
| 2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.sql;
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | * This interface provides a mechanism for executing SQL statements.
|
|---|
| 43 | *
|
|---|
| 44 | * @author Aaron M. Renn ([email protected])
|
|---|
| 45 | */
|
|---|
| 46 | public interface Statement
|
|---|
| 47 | {
|
|---|
| 48 |
|
|---|
| 49 | /**
|
|---|
| 50 | * This method executes the specified SQL SELECT statement and returns a
|
|---|
| 51 | * (possibly empty) <code>ResultSet</code> with the results of the query.
|
|---|
| 52 | *
|
|---|
| 53 | * @param sql The SQL statement to execute.
|
|---|
| 54 | *
|
|---|
| 55 | * @return The result set of the SQL statement.
|
|---|
| 56 | *
|
|---|
| 57 | * @exception SQLException If an error occurs.
|
|---|
| 58 | */
|
|---|
| 59 | public abstract ResultSet
|
|---|
| 60 | executeQuery(String sql) throws SQLException;
|
|---|
| 61 |
|
|---|
| 62 | /*************************************************************************/
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * This method executes the specified SQL INSERT, UPDATE, or DELETE statement
|
|---|
| 66 | * and returns the number of rows affected, which may be 0.
|
|---|
| 67 | *
|
|---|
| 68 | * @param sql The SQL statement to execute.
|
|---|
| 69 | *
|
|---|
| 70 | * @return The number of rows affected by the SQL statement.
|
|---|
| 71 | *
|
|---|
| 72 | * @exception SQLException If an error occurs.
|
|---|
| 73 | */
|
|---|
| 74 | public abstract int
|
|---|
| 75 | executeUpdate(String sql) throws SQLException;
|
|---|
| 76 |
|
|---|
| 77 | /*************************************************************************/
|
|---|
| 78 |
|
|---|
| 79 | /**
|
|---|
| 80 | * This method closes the statement and frees any associated resources.
|
|---|
| 81 | *
|
|---|
| 82 | * @exception SQLException If an error occurs.
|
|---|
| 83 | */
|
|---|
| 84 | public abstract void
|
|---|
| 85 | close() throws SQLException;
|
|---|
| 86 |
|
|---|
| 87 | /*************************************************************************/
|
|---|
| 88 |
|
|---|
| 89 | /**
|
|---|
| 90 | * This method returns the maximum length of any column value in bytes.
|
|---|
| 91 | *
|
|---|
| 92 | * @return The maximum length of any column value in bytes.
|
|---|
| 93 | *
|
|---|
| 94 | * @exception SQLException If an error occurs.
|
|---|
| 95 | */
|
|---|
| 96 | public abstract int
|
|---|
| 97 | getMaxFieldSize() throws SQLException;
|
|---|
| 98 |
|
|---|
| 99 | /*************************************************************************/
|
|---|
| 100 |
|
|---|
| 101 | /**
|
|---|
| 102 | * This method sets the limit for the maximum length of any column in bytes.
|
|---|
| 103 | *
|
|---|
| 104 | * @param maxsize The new maximum length of any column in bytes.
|
|---|
| 105 | *
|
|---|
| 106 | * @exception SQLException If an error occurs.
|
|---|
| 107 | */
|
|---|
| 108 | public abstract void
|
|---|
| 109 | setMaxFieldSize(int maxsize) throws SQLException;
|
|---|
| 110 |
|
|---|
| 111 | /*************************************************************************/
|
|---|
| 112 |
|
|---|
| 113 | /**
|
|---|
| 114 | * This method returns the maximum possible number of rows in a result set.
|
|---|
| 115 | *
|
|---|
| 116 | * @return The maximum possible number of rows in a result set.
|
|---|
| 117 | *
|
|---|
| 118 | * @exception SQLException If an error occurs.
|
|---|
| 119 | */
|
|---|
| 120 | public abstract int
|
|---|
| 121 | getMaxRows() throws SQLException;
|
|---|
| 122 |
|
|---|
| 123 | /*************************************************************************/
|
|---|
| 124 |
|
|---|
| 125 | /**
|
|---|
| 126 | * This method sets the maximum number of rows that can be present in a
|
|---|
| 127 | * result set.
|
|---|
| 128 | *
|
|---|
| 129 | * @param maxrows The maximum possible number of rows in a result set.
|
|---|
| 130 | *
|
|---|
| 131 | * @exception SQLException If an error occurs.
|
|---|
| 132 | */
|
|---|
| 133 | public abstract void
|
|---|
| 134 | setMaxRows(int maxrows) throws SQLException;
|
|---|
| 135 |
|
|---|
| 136 | /*************************************************************************/
|
|---|
| 137 |
|
|---|
| 138 | /**
|
|---|
| 139 | * This method sets the local escape processing mode on or off. The
|
|---|
| 140 | * default value is on.
|
|---|
| 141 | *
|
|---|
| 142 | * @param escape <code>true</code> to enable local escape processing,
|
|---|
| 143 | * <code>false</code> to disable it.
|
|---|
| 144 | *
|
|---|
| 145 | * @exception SQLException If an error occurs.
|
|---|
| 146 | */
|
|---|
| 147 | public abstract void
|
|---|
| 148 | setEscapeProcessing(boolean esacpe) throws SQLException;
|
|---|
| 149 |
|
|---|
| 150 | /*************************************************************************/
|
|---|
| 151 |
|
|---|
| 152 | /**
|
|---|
| 153 | * The method returns the number of seconds a statement may be in process
|
|---|
| 154 | * before timing out. A value of 0 means there is no timeout.
|
|---|
| 155 | *
|
|---|
| 156 | * @return The SQL statement timeout in seconds.
|
|---|
| 157 | *
|
|---|
| 158 | * @exception SQLException If an error occurs.
|
|---|
| 159 | */
|
|---|
| 160 | public abstract int
|
|---|
| 161 | getQueryTimeout() throws SQLException;
|
|---|
| 162 |
|
|---|
| 163 | /*************************************************************************/
|
|---|
| 164 |
|
|---|
| 165 | /**
|
|---|
| 166 | * This method sets the number of seconds a statement may be in process
|
|---|
| 167 | * before timing out. A value of 0 means there is no timeout.
|
|---|
| 168 | *
|
|---|
| 169 | * @param timeout The new SQL statement timeout value.
|
|---|
| 170 | *
|
|---|
| 171 | * @exception SQLException If an error occurs.
|
|---|
| 172 | */
|
|---|
| 173 | public abstract void
|
|---|
| 174 | setQueryTimeout(int timeout) throws SQLException;
|
|---|
| 175 |
|
|---|
| 176 | /*************************************************************************/
|
|---|
| 177 |
|
|---|
| 178 | /**
|
|---|
| 179 | * This method cancels an outstanding statement, if the database supports
|
|---|
| 180 | * that operation.
|
|---|
| 181 | *
|
|---|
| 182 | * @exception SQLException If an error occurs.
|
|---|
| 183 | */
|
|---|
| 184 | public abstract void
|
|---|
| 185 | cancel() throws SQLException;
|
|---|
| 186 |
|
|---|
| 187 | /*************************************************************************/
|
|---|
| 188 |
|
|---|
| 189 | /**
|
|---|
| 190 | * This method returns the first SQL warning attached to this statement.
|
|---|
| 191 | * Subsequent warnings will be chained to this one.
|
|---|
| 192 | *
|
|---|
| 193 | * @return The first SQL warning for this statement.
|
|---|
| 194 | *
|
|---|
| 195 | * @exception SQLException If an error occurs.
|
|---|
| 196 | */
|
|---|
| 197 | public abstract SQLWarning
|
|---|
| 198 | getWarnings() throws SQLException;
|
|---|
| 199 |
|
|---|
| 200 | /*************************************************************************/
|
|---|
| 201 |
|
|---|
| 202 | /**
|
|---|
| 203 | * This method clears any SQL warnings that have been attached to this
|
|---|
| 204 | * statement.
|
|---|
| 205 | *
|
|---|
| 206 | * @exception SQLException If an error occurs.
|
|---|
| 207 | */
|
|---|
| 208 | public abstract void
|
|---|
| 209 | clearWarnings() throws SQLException;
|
|---|
| 210 |
|
|---|
| 211 | /*************************************************************************/
|
|---|
| 212 |
|
|---|
| 213 | /**
|
|---|
| 214 | * This method sets the cursor name that will be used by the result set.
|
|---|
| 215 | *
|
|---|
| 216 | * @param name The cursor name to use for this statement.
|
|---|
| 217 | *
|
|---|
| 218 | * @exception SQLException If an error occurs.
|
|---|
| 219 | */
|
|---|
| 220 | public abstract void
|
|---|
| 221 | setCursorName(String name) throws SQLException;
|
|---|
| 222 |
|
|---|
| 223 | /*************************************************************************/
|
|---|
| 224 |
|
|---|
| 225 | /**
|
|---|
| 226 | * This method executes an arbitrary SQL statement of any time. The
|
|---|
| 227 | * methods <code>getResultSet</code>, <code>getMoreResults</code> and
|
|---|
| 228 | * <code>getUpdateCount</code> retrieve the results.
|
|---|
| 229 | *
|
|---|
| 230 | * @return <code>true</code> if a result set was returned, <code>false</code>
|
|---|
| 231 | * if an update count was returned.
|
|---|
| 232 | *
|
|---|
| 233 | * @exception SQLException If an error occurs.
|
|---|
| 234 | */
|
|---|
| 235 | public abstract boolean
|
|---|
| 236 | execute(String sql) throws SQLException;
|
|---|
| 237 |
|
|---|
| 238 | /*************************************************************************/
|
|---|
| 239 |
|
|---|
| 240 | /**
|
|---|
| 241 | * This method returns the result set of the SQL statement that was
|
|---|
| 242 | * executed. This should be called only once per result set returned.
|
|---|
| 243 | *
|
|---|
| 244 | * @return The result set of the query, or <code>null</code> if there was
|
|---|
| 245 | * no result set (for example, if the statement was an UPDATE).
|
|---|
| 246 | *
|
|---|
| 247 | * @exception SQLException If an error occurs.
|
|---|
| 248 | *
|
|---|
| 249 | * @see execute
|
|---|
| 250 | */
|
|---|
| 251 | public abstract ResultSet
|
|---|
| 252 | getResultSet() throws SQLException;
|
|---|
| 253 |
|
|---|
| 254 | /*************************************************************************/
|
|---|
| 255 |
|
|---|
| 256 | /**
|
|---|
| 257 | * This method returns the update count of the SQL statement that was
|
|---|
| 258 | * executed. This should be called only once per executed SQL statement.
|
|---|
| 259 | *
|
|---|
| 260 | * @return The update count of the query, or -1 if there was no update
|
|---|
| 261 | * count (for example, if the statement was a SELECT).
|
|---|
| 262 | *
|
|---|
| 263 | * @exception SQLException If an error occurs.
|
|---|
| 264 | *
|
|---|
| 265 | * @see execute
|
|---|
| 266 | */
|
|---|
| 267 | public abstract int
|
|---|
| 268 | getUpdateCount() throws SQLException;
|
|---|
| 269 |
|
|---|
| 270 | /*************************************************************************/
|
|---|
| 271 |
|
|---|
| 272 | /**
|
|---|
| 273 | * This method advances the result set pointer to the next result set,
|
|---|
| 274 | * which can then be retrieved using <code>getResultSet</code>
|
|---|
| 275 | *
|
|---|
| 276 | * @return <code>true</code> if there is another result set,
|
|---|
| 277 | * <code>false</code> otherwise (for example, the next result is an
|
|---|
| 278 | * update count).
|
|---|
| 279 | *
|
|---|
| 280 | * @exception SQLException If an error occurs.
|
|---|
| 281 | *
|
|---|
| 282 | * @see execute
|
|---|
| 283 | */
|
|---|
| 284 | public abstract boolean
|
|---|
| 285 | getMoreResults() throws SQLException;
|
|---|
| 286 |
|
|---|
| 287 | /*************************************************************************/
|
|---|
| 288 |
|
|---|
| 289 | /**
|
|---|
| 290 | * This method returns the current direction that the driver thinks the
|
|---|
| 291 | * result set will be accessed int.
|
|---|
| 292 | *
|
|---|
| 293 | * @return The direction the result set will be accessed in (????)
|
|---|
| 294 | *
|
|---|
| 295 | * @exception SQLException If an error occurs.
|
|---|
| 296 | */
|
|---|
| 297 | public abstract int
|
|---|
| 298 | getFetchDirection() throws SQLException;
|
|---|
| 299 |
|
|---|
| 300 | /*************************************************************************/
|
|---|
| 301 |
|
|---|
| 302 | /**
|
|---|
| 303 | * This method informs the driver which direction the result set will
|
|---|
| 304 | * be accessed in.
|
|---|
| 305 | *
|
|---|
| 306 | * @param direction The direction the result set will be accessed in (?????)
|
|---|
| 307 | *
|
|---|
| 308 | * @exception SQLException If an error occurs.
|
|---|
| 309 | */
|
|---|
| 310 | public abstract void
|
|---|
| 311 | setFetchDirection(int direction) throws SQLException;
|
|---|
| 312 |
|
|---|
| 313 | /*************************************************************************/
|
|---|
| 314 |
|
|---|
| 315 | /**
|
|---|
| 316 | * This method returns the number of rows the driver believes should be
|
|---|
| 317 | * fetched from the database at a time.
|
|---|
| 318 | *
|
|---|
| 319 | * @return The number of rows that will be fetched from the database at a time.
|
|---|
| 320 | *
|
|---|
| 321 | * @exception SQLException If an error occurs.
|
|---|
| 322 | */
|
|---|
| 323 | public abstract int
|
|---|
| 324 | getFetchSize() throws SQLException;
|
|---|
| 325 |
|
|---|
| 326 | /*************************************************************************/
|
|---|
| 327 |
|
|---|
| 328 | /**
|
|---|
| 329 | * This method informs the driver how many rows it should fetch from the
|
|---|
| 330 | * database at a time.
|
|---|
| 331 | *
|
|---|
| 332 | * @param numrows The number of rows the driver should fetch at a time
|
|---|
| 333 | * to populate the result set.
|
|---|
| 334 | *
|
|---|
| 335 | * @exception SQLException If an error occurs.
|
|---|
| 336 | */
|
|---|
| 337 | public abstract void
|
|---|
| 338 | setFetchSize(int numrows) throws SQLException;
|
|---|
| 339 |
|
|---|
| 340 | /*************************************************************************/
|
|---|
| 341 |
|
|---|
| 342 | /**
|
|---|
| 343 | * This method returns the concurrency type of the result set for this
|
|---|
| 344 | * statement. This will be one of the concurrency types defined in
|
|---|
| 345 | * <code>ResultSet</code>.
|
|---|
| 346 | *
|
|---|
| 347 | * @return The concurrency type of the result set for this statement.
|
|---|
| 348 | *
|
|---|
| 349 | * @exception SQLException If an error occurs.
|
|---|
| 350 | *
|
|---|
| 351 | * @see ResultSet
|
|---|
| 352 | */
|
|---|
| 353 | public abstract int
|
|---|
| 354 | getResultSetConcurrency() throws SQLException;
|
|---|
| 355 |
|
|---|
| 356 | /*************************************************************************/
|
|---|
| 357 |
|
|---|
| 358 | /**
|
|---|
| 359 | * This method returns the result set type for this statement. This will
|
|---|
| 360 | * be one of the result set types defined in <code>ResultSet</code>.
|
|---|
| 361 | *
|
|---|
| 362 | * @return The result set type for this statement.
|
|---|
| 363 | *
|
|---|
| 364 | * @exception SQLException If an error occurs.
|
|---|
| 365 | *
|
|---|
| 366 | * @see ResultSet
|
|---|
| 367 | */
|
|---|
| 368 | public abstract int
|
|---|
| 369 | getResultSetType() throws SQLException;
|
|---|
| 370 |
|
|---|
| 371 | /*************************************************************************/
|
|---|
| 372 |
|
|---|
| 373 | /**
|
|---|
| 374 | * This method adds a SQL statement to a SQL batch. A driver is not
|
|---|
| 375 | * required to implement this method.
|
|---|
| 376 | *
|
|---|
| 377 | * @param sql The sql statement to add to the batch.
|
|---|
| 378 | *
|
|---|
| 379 | * @exception SQLException If an error occurs.
|
|---|
| 380 | */
|
|---|
| 381 | public abstract void
|
|---|
| 382 | addBatch(String sql) throws SQLException;
|
|---|
| 383 |
|
|---|
| 384 | /*************************************************************************/
|
|---|
| 385 |
|
|---|
| 386 | /**
|
|---|
| 387 | * This method clears out any SQL statements that have been populated in
|
|---|
| 388 | * the current batch. A driver is not required to implement this method.
|
|---|
| 389 | *
|
|---|
| 390 | * @exception SQLException If an error occurs.
|
|---|
| 391 | */
|
|---|
| 392 | public abstract void
|
|---|
| 393 | clearBatch() throws SQLException;
|
|---|
| 394 |
|
|---|
| 395 | /*************************************************************************/
|
|---|
| 396 |
|
|---|
| 397 | /**
|
|---|
| 398 | * This method executes the SQL batch and returns an array of update
|
|---|
| 399 | * counts - one for each SQL statement in the batch - ordered in the same
|
|---|
| 400 | * order the statements were added to the batch. A driver is not required
|
|---|
| 401 | * to implement this method.
|
|---|
| 402 | *
|
|---|
| 403 | * @return An array of update counts for this batch.
|
|---|
| 404 | *
|
|---|
| 405 | * @exception SQLException If an error occurs.
|
|---|
| 406 | */
|
|---|
| 407 | public abstract int[]
|
|---|
| 408 | executeBatch() throws SQLException;
|
|---|
| 409 |
|
|---|
| 410 | /*************************************************************************/
|
|---|
| 411 |
|
|---|
| 412 | /**
|
|---|
| 413 | * This method returns the <code>Connection</code> instance that was
|
|---|
| 414 | * used to create this object.
|
|---|
| 415 | *
|
|---|
| 416 | * @return The connection used to create this object.
|
|---|
| 417 | *
|
|---|
| 418 | * @exception SQLException If an error occurs.
|
|---|
| 419 | */
|
|---|
| 420 | public abstract Connection
|
|---|
| 421 | getConnection() throws SQLException;
|
|---|
| 422 |
|
|---|
| 423 | } // interface Statement
|
|---|
| 424 |
|
|---|