/gcc-3.2.3-20040701/libjava/java/sql/Statement.java

# · Java · 424 lines · 60 code · 60 blank · 304 comment · 0 complexity · 6bd71e76bfc952741b08dae9d3fe73f0 MD5 · raw file

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