/projects/derby-10.9.1.0/db-derby-10.9.1.0-src/java/stubs/jsr169/java/sql/Statement.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 620 lines · 52 code · 46 blank · 522 comment · 0 complexity · 26d32a3a7c7e9590b8a70e7b65e73d2b MD5 · raw file

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package java.sql;
  18. /**
  19. * Interface used for executing static SQL statements and returning their
  20. * results.
  21. *
  22. * By default, an object implementing the Statement interface can returns
  23. * results as ResultSets. For any given Statement object, only one ResultSet can
  24. * be open at one time. A call to any of the execution methods of Statement will
  25. * cause any previously created ResultSet object for that Statement to be closed
  26. * implicitly.
  27. * <p>
  28. * To have multiple ResultSet objects open concurrently, multiple Statement
  29. * objects must be used.
  30. */
  31. public interface Statement {
  32. /**
  33. * Passing this constant to getMoreResults implies that all ResultSet
  34. * objects previously kept open should be closed.
  35. */
  36. public static final int CLOSE_ALL_RESULTS = 3;
  37. /**
  38. * Passing this constant to getMoreResults implies that the current
  39. * ResultSet object should be closed
  40. */
  41. public static final int CLOSE_CURRENT_RESULT = 1;
  42. /**
  43. * Indicates that an error was encountered during execution of a batch
  44. * statement.
  45. */
  46. public static final int EXECUTE_FAILED = -3;
  47. /**
  48. * Passing this constant to getMoreResults implies that the current
  49. * ResultSet object should not be closed.
  50. */
  51. public static final int KEEP_CURRENT_RESULT = 2;
  52. /**
  53. * Indicates that generated keys should not be accessible for retrieval.
  54. */
  55. public static final int NO_GENERATED_KEYS = 2;
  56. /**
  57. * Indicates that generated keys should be accessible for retrieval.
  58. */
  59. public static final int RETURN_GENERATED_KEYS = 1;
  60. /**
  61. * Indicates that a batch statement was executed with a successful result,
  62. * but a count of the number of rows it affected is unavailable.
  63. */
  64. public static final int SUCCESS_NO_INFO = -2;
  65. /**
  66. * Adds a specified SQL commands to the list of commands for this Statement.
  67. * <p>
  68. * The list of commands is executed by invoking the
  69. * <code>executeBatch</code> method.
  70. *
  71. * @param sql
  72. * the SQL command as a String. Typically an INSERT or UPDATE
  73. * statement.
  74. * @throws SQLException
  75. * if an error occurs accessing the database or the database
  76. * does not support batch updates
  77. */
  78. public void addBatch(String sql) throws SQLException;
  79. /**
  80. * Cancels this Statement execution if both the database and the JDBC driver
  81. * support aborting an SQL statement in flight. This method can be used by
  82. * one thread to stop a Statement that is being executed on another thread.
  83. *
  84. * @throws SQLException
  85. * if an error occurs accessing the database
  86. */
  87. public void cancel() throws SQLException;
  88. /**
  89. * Clears the current list of SQL commands for this Statement.
  90. *
  91. * @throws SQLException
  92. * if an error occurs accessing the database or the database
  93. * does not support batch updates
  94. */
  95. public void clearBatch() throws SQLException;
  96. /**
  97. * Clears all SQLWarnings from this Statement.
  98. *
  99. * @throws SQLException
  100. * if an error occurs accessing the database
  101. */
  102. public void clearWarnings() throws SQLException;
  103. /**
  104. * Releases this Statement's database and JDBC driver resources.
  105. * <p>
  106. * Using this method to release these resources as soon as possible is
  107. * strongly recommended. It is not a good idea to rely on these resources
  108. * being released when the Statement object is finalized during garbage
  109. * collection. Doing so can result in unpredictable performance
  110. * characteristics for the application.
  111. *
  112. * @throws SQLException
  113. * if an error occurs accessing the database
  114. */
  115. public void close() throws SQLException;
  116. /**
  117. * Executes a supplied SQL statement. This may return multiple ResultSets.
  118. * <p>
  119. * Use the <code>getResultSet</code> or <code>getUpdateCount</code>
  120. * methods to get the first result and <code>getMoreResults</code> to get
  121. * any subsequent results.
  122. *
  123. * @param sql
  124. * the SQL statement to execute
  125. * @return true if the first result is a ResultSet, false if the first
  126. * result is an update count or if there is no result
  127. * @throws SQLException
  128. * if an error occurs accessing the database
  129. */
  130. public boolean execute(String sql) throws SQLException;
  131. /**
  132. * Executes a supplied SQL statement. This may return multiple ResultSets.
  133. * This method allows control of whether auto-generated Keys should be made
  134. * available for retrieval, if the SQL statement is an INSERT statement.
  135. * <p>
  136. * Use the <code>getResultSet</code> or <code>getUpdateCount</code>
  137. * methods to get the first result and <code>getMoreResults</code> to get
  138. * any subsequent results.
  139. *
  140. * @param sql
  141. * the SQL statement to execute
  142. * @param autoGeneratedKeys
  143. * a flag indicating whether to make auto generated keys
  144. * available for retrieval. This parameter must be one of
  145. * Statement.NO_GENERATED_KEYS or Statement.RETURN_GENERATED_KEYS
  146. * @return true if results exists and the first result is a ResultSet, false
  147. * if the first result is an update count or if there is no result
  148. * @throws SQLException
  149. * if an error occurs accessing the database
  150. */
  151. public boolean execute(String sql, int autoGeneratedKeys)
  152. throws SQLException;
  153. /**
  154. * Executes the supplied SQL statement. This may return multiple ResultSets.
  155. * This method allows retrieval of auto generated keys specified by the
  156. * supplied array of column indexes, if the SQL statement is an INSERT
  157. * statement.
  158. * <p>
  159. * Use the <code>getResultSet</code> or <code>getUpdateCount</code>
  160. * methods to get the first result and <code>getMoreResults</code> to get
  161. * any subsequent results.
  162. *
  163. * @param sql
  164. * the SQL statement to execute
  165. * @param columnIndexes
  166. * an array of indexes of the columns in the inserted row which
  167. * should be made available for retrieval via the
  168. * <code>getGeneratedKeys</code> method.
  169. * @return true if the first result is a ResultSet, false if the first
  170. * result is an update count or if there is no result
  171. * @throws SQLException
  172. * if an error occurs accessing the database
  173. */
  174. public boolean execute(String sql, int[] columnIndexes) throws SQLException;
  175. /**
  176. * Executes the supplied SQL statement. This may return multiple ResultSets.
  177. * This method allows retrieval of auto generated keys specified by the
  178. * supplied array of column indexes, if the SQL statement is an INSERT
  179. * statement.
  180. * <p>
  181. * Use the <code>getResultSet</code> or <code>getUpdateCount</code>
  182. * methods to get the first result and <code>getMoreResults</code> to get
  183. * any subsequent results.
  184. *
  185. * @param sql
  186. * the SQL statement to execute
  187. * @param columnNames
  188. * an array of column names in the inserted row which should be
  189. * made available for retrieval via the
  190. * <code>getGeneratedKeys</code> method.
  191. * @return true if the first result is a ResultSet, false if the first
  192. * result is an update count or if there is no result
  193. * @throws SQLException
  194. * if an error occurs accessing the database
  195. */
  196. public boolean execute(String sql, String[] columnNames)
  197. throws SQLException;
  198. /**
  199. * Submits a batch of SQL commands to the database. Returns an array of
  200. * update counts, if all the commands execute successfully.
  201. * <p>
  202. * If one of the commands in the batch fails, this method can throw a
  203. * BatchUpdateException and the JDBC driver may or may not process the
  204. * remaining commands. The JDBC driver must behave consistently with the
  205. * underlying database, either always continuing or never continuing. If the
  206. * driver continues processing, the array of results returned contains the
  207. * same number of elements as there are commands in the batch, with a
  208. * minimum of one of the elements having the EXECUTE_FAILED value.
  209. *
  210. * @return an array of update counts, with one entry for each command in the
  211. * batch. The elements are ordered according to the order in which
  212. * the commands were added to the batch.
  213. * <p>
  214. * <ol>
  215. * <li> If the value of an element is >=0, the corresponding command
  216. * completed successfully and the value is the update count for that
  217. * command, which is the number of rows in the database affected by
  218. * the command.</li>
  219. * <li> If the value is SUCCESS_NO_INFO, the command completed
  220. * successfully but the number of rows affected is unknown.
  221. * <li>
  222. * <li> If the value is EXECUTE_FAILED, the command failed.
  223. * </ol>
  224. * @throws SQLException
  225. * if an error occurs accessing the database
  226. */
  227. public int[] executeBatch() throws SQLException;
  228. /**
  229. * Executes a supplied SQL statement. Returns a single ResultSet.
  230. *
  231. * @param sql
  232. * an SQL statement to execute. Typically a SELECT statement
  233. * @return a ResultSet containing the data produced by the SQL statement.
  234. * Never null.
  235. * @throws SQLException
  236. * if an error occurs accessing the database or if the statement
  237. * produces anything other than a single ResultSet
  238. */
  239. public ResultSet executeQuery(String sql) throws SQLException;
  240. /**
  241. * Executes the supplied SQL statement. The statement may be an INSERT,
  242. * UPDATE or DELETE statement or a statement which returns nothing.
  243. *
  244. * @param sql
  245. * an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or
  246. * a statement which returns nothing
  247. * @return the count of updated rows, or 0 for a statement that returns
  248. * nothing.
  249. * @throws SQLException
  250. * if an error occurs accessing the database or if the statement
  251. * produces a ResultSet
  252. */
  253. public int executeUpdate(String sql) throws SQLException;
  254. /**
  255. * Executes the supplied SQL statement. This method allows control of
  256. * whether auto-generated Keys should be made available for retrieval.
  257. *
  258. * @param sql
  259. * an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or
  260. * a statement which does not return anything.
  261. * @param autoGeneratedKeys
  262. * a flag that indicates whether to allow retrieval of auto
  263. * generated keys. Parameter must be one of
  264. * Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS
  265. * @return the number of updated rows, or 0 if the statement returns
  266. * nothing.
  267. * @throws SQLException
  268. * if an error occurs accessing the database or if the statement
  269. * produces a ResultSet
  270. */
  271. public int executeUpdate(String sql, int autoGeneratedKeys)
  272. throws SQLException;
  273. /**
  274. * Executes the supplied SQL statement. This method allows retrieval of auto
  275. * generated keys specified by the supplied array of column indexes.
  276. *
  277. * @param sql
  278. * an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or
  279. * a statement which returns nothing
  280. * @param columnIndexes
  281. * an array of indexes of the columns in the inserted row which
  282. * should be made available for retrieval via the
  283. * <code>getGeneratedKeys</code> method.
  284. * @return the count of updated rows, or 0 for a statement that returns
  285. * nothing.
  286. * @throws SQLException
  287. * if an error occurs accessing the database or if the statement
  288. * produces a ResultSet
  289. */
  290. public int executeUpdate(String sql, int[] columnIndexes)
  291. throws SQLException;
  292. /**
  293. * Executes the supplied SQL statement. This method allows retrieval of auto
  294. * generated keys specified by the supplied array of column names.
  295. *
  296. * @param sql
  297. * an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or
  298. * a statement which returns nothing
  299. * @param columnNames
  300. * an array of column names in the inserted row which should be
  301. * made available for retrieval via the
  302. * <code>getGeneratedKeys</code> method.
  303. * @return the count of updated rows, or 0 for a statement that returns
  304. * nothing.
  305. * @throws SQLException
  306. * if an error occurs accessing the database or if the statement
  307. * produces a ResultSet
  308. */
  309. public int executeUpdate(String sql, String[] columnNames)
  310. throws SQLException;
  311. /**
  312. * Gets the Connection that produced this Statement.
  313. *
  314. * @return the Connection
  315. * @throws SQLException
  316. * if an error occurs accessing the database
  317. */
  318. public Connection getConnection() throws SQLException;
  319. /**
  320. * Gets the default direction for fetching rows for ResultSets generated
  321. * from this Statement.
  322. *
  323. * @return an integer describing the default fetch direction, one of:
  324. * ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE,
  325. * ResultSet.FETCH_UNKNOWN
  326. * @throws SQLException
  327. * if an error occurs accessing the database
  328. */
  329. public int getFetchDirection() throws SQLException;
  330. /**
  331. * Gets the default number of rows for a fetch for the ResultSet objects
  332. * returned from this Statement.
  333. *
  334. * @return the default fetch size for ResultSets produced by this Statement
  335. * @throws SQLException
  336. * if an error occurs accessing the database
  337. */
  338. public int getFetchSize() throws SQLException;
  339. /**
  340. * Returns auto generated keys created by executing this Statement.
  341. *
  342. * @return a ResultSet containing the auto generated keys - empty if no keys
  343. * were generated by the Statement
  344. * @throws SQLException
  345. * if an error occurs accessing the database
  346. */
  347. public ResultSet getGeneratedKeys() throws SQLException;
  348. /**
  349. * Gets the maximum number of bytes which can be returned for values from
  350. * Character and Binary values in a ResultSet derived from this Statement.
  351. * This limit applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR,
  352. * and LONGVARCHAR types. Any data exceeding the maximum size is abandoned
  353. * without announcement.
  354. *
  355. * @return the current size limit, where 0 means that there is no limit
  356. * @throws SQLException
  357. * if an error occurs accessing the database
  358. */
  359. public int getMaxFieldSize() throws SQLException;
  360. /**
  361. * Gets the maximum number of rows that a ResultSet can contain when
  362. * produced from this Statement. If the limit is exceeded, the excess rows
  363. * are discarded silently.
  364. *
  365. * @return the current row limit, where 0 means that there is no limit.
  366. * @throws SQLException
  367. * if an error occurs accessing the database
  368. */
  369. public int getMaxRows() throws SQLException;
  370. /**
  371. * Moves to this Statement's next result. Returns true if it is a ResultSet.
  372. * Any current ResultSet objects previously obtained with
  373. * <code>getResultSet()</code> are closed implicitly.
  374. *
  375. * @return true if the next result is a ResultSet, false if the next result
  376. * is not a ResultSet or if there are no more results. Note that if
  377. * there is no more data, this method will return false and
  378. * <code>getUpdateCount</code> will return -1.
  379. * @throws SQLException
  380. * if an error occurs accessing the database
  381. */
  382. public boolean getMoreResults() throws SQLException;
  383. /**
  384. * Moves to this Statement's next result. Returns true if the next result is
  385. * a ResultSet. Any current ResultSet objects previously obtained with
  386. * <code>getResultSet()</code> are handled as indicated by a supplied Flag
  387. * parameter.
  388. *
  389. * @param current
  390. * a flag indicating what to do with existing ResultSets. This
  391. * parameter must be one of Statement.CLOSE_ALL_RESULTS,
  392. * Statement.CLOSE_CURRENT_RESULT or
  393. * Statement.KEEP_CURRENT_RESULT.
  394. * @return true if the next result exists and is a ResultSet, false if the
  395. * next result is not a ResultSet or if there are no more results.
  396. * Note that if there is no more data, this method will return false
  397. * and <code>getUpdateCount</code> will return -1.
  398. * @throws SQLException
  399. * if an error occurs accessing the database
  400. */
  401. public boolean getMoreResults(int current) throws SQLException;
  402. /**
  403. * Gets the timeout value for Statement execution. The JDBC driver will wait
  404. * up to this value for the execution to complete - after the limit is
  405. * exceeded an SQL Exception is thrown.
  406. *
  407. * @return the current Query Timeout value, where 0 indicates that there is
  408. * no current timeout.
  409. * @throws SQLException
  410. * if an error occurs accessing the database
  411. */
  412. public int getQueryTimeout() throws SQLException;
  413. /**
  414. * Gets the current result. Should only be called once per result.
  415. *
  416. * @return the ResultSet for the current result. null if the result is an
  417. * update count or if there are no more results.
  418. * @throws SQLException
  419. * if an error occurs accessing the database
  420. */
  421. public ResultSet getResultSet() throws SQLException;
  422. /**
  423. * Gets the concurrency setting for ResultSet objects generated by this
  424. * Statement.
  425. *
  426. * @return ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
  427. * @throws SQLException
  428. * if an error occurs accessing the database
  429. */
  430. public int getResultSetConcurrency() throws SQLException;
  431. /**
  432. * Gets the cursor hold setting for ResultSet objects generated by this
  433. * Statement.
  434. *
  435. * @return ResultSet.HOLD_CURSORS_OVER_COMMIT or
  436. * ResultSet.CLOSE_CURSORS_AT_COMMIT
  437. * @throws SQLException
  438. * if there is an error while accessing the database
  439. */
  440. public int getResultSetHoldability() throws SQLException;
  441. /**
  442. * Gets the ResultSet type setting for ResultSets derived from this
  443. * Statement.
  444. *
  445. * @return ResultSet.TYPE_FORWARD_ONLY for a ResultSet where the cursor can
  446. * only move forward, ResultSet.TYPE_SCROLL_INSENSITIVE for a
  447. * ResultSet which is Scrollable but is not sensitive to changes
  448. * made by others, ResultSet.TYPE_SCROLL_SENSITIVE for a ResultSet
  449. * which is Scrollable but is sensitive to changes made by others
  450. * @throws SQLException
  451. * if there is an error accessing the database
  452. */
  453. public int getResultSetType() throws SQLException;
  454. /**
  455. * Gets an update count for the current result if it is not a ResultSet.
  456. *
  457. * @return the current result as an update count. -1 if the current result
  458. * is a ResultSet or if there are no more results
  459. * @throws SQLException
  460. * if an error occurs accessing the database
  461. */
  462. public int getUpdateCount() throws SQLException;
  463. /**
  464. * Retrieves the first SQLWarning reported by calls on this Statement.
  465. * <p>
  466. * If there are multiple warnings, subsequent warnings are chained to the
  467. * first one.
  468. * <p>
  469. * The chain or warnings is cleared each time the Statement is executed.
  470. * <p>
  471. * Warnings associated with reads from the ResultSet returned from executing
  472. * a Statement will be attached to the ResultSet, not the Statement object.
  473. *
  474. * @return an SQLWarning, null if there are no warnings
  475. * @throws SQLException
  476. * if an error occurs accessing the database
  477. */
  478. public SQLWarning getWarnings() throws SQLException;
  479. /**
  480. * Sets the SQL cursor name. This name is used by subsequent Statement
  481. * execute methods.
  482. * <p>
  483. * Cursor names must be unique within one Connection.
  484. * <p>
  485. * With the Cursor name set, it can then be utilized in SQL positioned
  486. * update or delete statements to determine the current row in a ResultSet
  487. * generated from this Statement. The positioned update or delete must be
  488. * done with a different Statement than this one.
  489. *
  490. * @param name
  491. * the Cursor name as a String,
  492. * @throws SQLException
  493. * if an error occurs accessing the database
  494. */
  495. public void setCursorName(String name) throws SQLException;
  496. /**
  497. * Sets Escape Processing mode.
  498. * <p>
  499. * If Escape Processing is on, the JDBC driver will do escape substitution
  500. * on an SQL statement before sending it for execution. This does not apply
  501. * to PreparedStatements since they are processed when created, before this
  502. * method can be called.
  503. *
  504. * @param enable
  505. * true to set escape processing mode on, false to turn it off.
  506. * @throws SQLException
  507. * if an error occurs accessing the database
  508. */
  509. public void setEscapeProcessing(boolean enable) throws SQLException;
  510. /**
  511. * Sets the fetch direction - a hint to the JDBC driver about the direction
  512. * of processing of rows in ResultSets created by this Statement. The
  513. * default fetch direction is FETCH_FORWARD.
  514. *
  515. * @param direction
  516. * which fetch direction to use. This parameter should be one of
  517. * ResultSet.FETCH_UNKNOWN, ResultSet.FETCH_FORWARD or
  518. * ResultSet.FETCH_REVERSE
  519. * @throws SQLException
  520. * if there is an error while accessing the database or if the
  521. * fetch direction is unrecognized
  522. */
  523. public void setFetchDirection(int direction) throws SQLException;
  524. /**
  525. * Sets the fetch size. This is a hint to the JDBC driver about how many
  526. * rows should be fetched from the database when more are required by
  527. * application processing.
  528. *
  529. * @param rows
  530. * the number of rows that should be fetched. 0 tells the driver
  531. * to ignore the hint. Should be less than
  532. * <code>getMaxRows</code> for this statement. Should not be
  533. * negative.
  534. * @throws SQLException
  535. * if an error occurs accessing the database, or if the rows
  536. * parameter is out of range.
  537. */
  538. public void setFetchSize(int rows) throws SQLException;
  539. /**
  540. * Sets the maximum number of bytes for ResultSet columns that contain
  541. * character or binary values. This applies to BINARY, VARBINARY,
  542. * LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR fields. Any data exceeding
  543. * the maximum size is abandoned without announcement.
  544. *
  545. * @param max
  546. * the maximum field size in bytes. O means "no limit".
  547. * @throws SQLException
  548. * if an error occurs accessing the database or the max value is
  549. * <0.
  550. */
  551. public void setMaxFieldSize(int max) throws SQLException;
  552. /**
  553. * Sets the maximum number of rows that any ResultSet can contain. If the
  554. * number of rows exceeds this value, the additional rows are silently
  555. * discarded.
  556. *
  557. * @param max
  558. * the maximum number of rows. 0 means "no limit".
  559. * @throws SQLException
  560. * if an error occurs accessing the database or if max <0.
  561. */
  562. public void setMaxRows(int max) throws SQLException;
  563. /**
  564. * Sets the timeout, in seconds, for queries - how long the driver will
  565. * allow for completion of a Statement execution. If the timeout is
  566. * exceeded, the query will throw an SQLException.
  567. *
  568. * @param seconds
  569. * timeout in seconds. 0 means no timeout ("wait forever")
  570. * @throws SQLException
  571. * if an error occurs accessing the database or if seconds <0.
  572. */
  573. public void setQueryTimeout(int seconds) throws SQLException;
  574. }