PreparedStatement.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /* PreparedStatement.java -- Interface for pre-compiled statements.
  2. Copyright (C) 1999, 2000, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 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. import java.io.InputStream;
  33. import java.io.Reader;
  34. import java.math.BigDecimal;
  35. import java.net.URL;
  36. import java.util.Calendar;
  37. /**
  38. * This interface provides a mechanism for executing pre-compiled
  39. * statements. This provides greater efficiency when calling the same
  40. * statement multiple times. Parameters are allowed in a statement,
  41. * providings for maximum reusability.
  42. *
  43. * <p> Note that in this class parameter indices start at 1, not 0.</p>
  44. *
  45. * @author Aaron M. Renn (arenn@urbanophile.com)
  46. */
  47. public interface PreparedStatement extends Statement
  48. {
  49. /**
  50. * This method executes a prepared SQL query and returns its ResultSet.
  51. *
  52. * @return The ResultSet of the SQL statement.
  53. * @exception SQLException If an error occurs.
  54. */
  55. ResultSet executeQuery() throws SQLException;
  56. /**
  57. * This method executes an SQL INSERT, UPDATE or DELETE statement. SQL
  58. * statements that return nothing such as SQL DDL statements can be executed.
  59. *
  60. * @return The result is either the row count for INSERT, UPDATE or DELETE
  61. * statements; or 0 for SQL statements that return nothing.
  62. * @exception SQLException If an error occurs.
  63. */
  64. int executeUpdate() throws SQLException;
  65. /**
  66. * This method populates the specified parameter with a SQL NULL value
  67. * for the specified type.
  68. *
  69. * @param index The index of the parameter to set.
  70. * @param sqlType The SQL type identifier of the parameter from
  71. * <code>Types</code>
  72. *
  73. * @exception SQLException If an error occurs.
  74. */
  75. void setNull(int index, int sqlType) throws SQLException;
  76. /**
  77. * This method sets the specified parameter from the given Java
  78. * <code>boolean</code> value.
  79. *
  80. * @param index The index of the parameter value to set.
  81. * @param value The value of the parameter.
  82. * @exception SQLException If an error occurs.
  83. */
  84. void setBoolean(int index, boolean value) throws SQLException;
  85. /**
  86. * This method sets the specified parameter from the given Java
  87. * <code>byte</code> value.
  88. *
  89. * @param index The index of the parameter value to set.
  90. * @param value The value of the parameter.
  91. * @exception SQLException If an error occurs.
  92. */
  93. void setByte(int index, byte value) throws SQLException;
  94. /**
  95. * This method sets the specified parameter from the given Java
  96. * <code>short</code> value.
  97. *
  98. * @param index The index of the parameter value to set.
  99. * @param value The value of the parameter.
  100. * @exception SQLException If an error occurs.
  101. */
  102. void setShort(int index, short value) throws SQLException;
  103. /**
  104. * This method sets the specified parameter from the given Java
  105. * <code>int</code> value.
  106. *
  107. * @param index The index of the parameter value to set.
  108. * @param value The value of the parameter.
  109. * @exception SQLException If an error occurs.
  110. */
  111. void setInt(int index, int value) throws SQLException;
  112. /**
  113. * This method sets the specified parameter from the given Java
  114. * <code>long</code> value.
  115. *
  116. * @param index The index of the parameter value to set.
  117. * @param value The value of the parameter.
  118. * @exception SQLException If an error occurs.
  119. */
  120. void setLong(int index, long value) throws SQLException;
  121. /**
  122. * This method sets the specified parameter from the given Java
  123. * <code>float</code> value.
  124. *
  125. * @param index The index of the parameter value to set.
  126. * @param value The value of the parameter.
  127. * @exception SQLException If an error occurs.
  128. */
  129. void setFloat(int index, float value) throws SQLException;
  130. /**
  131. * This method sets the specified parameter from the given Java
  132. * <code>double</code> value.
  133. *
  134. * @param index The index of the parameter value to set.
  135. * @param value The value of the parameter.
  136. * @exception SQLException If an error occurs.
  137. */
  138. void setDouble(int index, double value) throws SQLException;
  139. /**
  140. * This method sets the specified parameter from the given Java
  141. * <code>java.math.BigDecimal</code> value.
  142. *
  143. * @param index The index of the parameter value to set.
  144. * @param value The value of the parameter.
  145. * @exception SQLException If an error occurs.
  146. */
  147. void setBigDecimal(int index, BigDecimal value) throws
  148. SQLException;
  149. /**
  150. * This method sets the specified parameter from the given Java
  151. * <code>String</code> value.
  152. *
  153. * @param index The index of the parameter value to set.
  154. * @param value The value of the parameter.
  155. * @exception SQLException If an error occurs.
  156. */
  157. void setString(int index, String value) throws SQLException;
  158. /**
  159. * This method sets the specified parameter from the given Java
  160. * <code>byte</code> array value.
  161. *
  162. * @param index The index of the parameter value to set.
  163. * @param value The value of the parameter.
  164. * @exception SQLException If an error occurs.
  165. */
  166. void setBytes(int index, byte[] value) throws SQLException;
  167. /**
  168. * This method sets the specified parameter from the given Java
  169. * <code>java.sql.Date</code> value.
  170. *
  171. * @param index The index of the parameter value to set.
  172. * @param value The value of the parameter.
  173. * @exception SQLException If an error occurs.
  174. */
  175. void setDate(int index, Date value) throws SQLException;
  176. /**
  177. * This method sets the specified parameter from the given Java
  178. * <code>java.sql.Time</code> value.
  179. *
  180. * @param index The index of the parameter value to set.
  181. * @param value The value of the parameter.
  182. * @exception SQLException If an error occurs.
  183. */
  184. void setTime(int index, Time value) throws SQLException;
  185. /**
  186. * This method sets the specified parameter from the given Java
  187. * <code>java.sql.Timestamp</code> value.
  188. *
  189. * @param index The index of the parameter value to set.
  190. * @param value The value of the parameter.
  191. * @exception SQLException If an error occurs.
  192. */
  193. void setTimestamp(int index, Timestamp value)
  194. throws SQLException;
  195. /**
  196. * This method sets the specified parameter from the given Java
  197. * ASCII <code>InputStream</code> value.
  198. *
  199. * @param index The index of the parameter value to set.
  200. * @param stream The stream from which the parameter value is read.
  201. * @param count The number of bytes in the stream.
  202. * @exception SQLException If an error occurs.
  203. */
  204. void setAsciiStream(int index, InputStream stream, int count)
  205. throws SQLException;
  206. /**
  207. * This method sets the specified parameter from the given Java
  208. * Unicode UTF-8 <code>InputStream</code> value.
  209. *
  210. * @param index The index of the parameter value to set.
  211. * @param stream The stream from which the parameter value is read.
  212. * @param count The number of bytes in the stream.
  213. * @exception SQLException If an error occurs.
  214. * @deprecated
  215. */
  216. void setUnicodeStream(int index, InputStream stream, int count)
  217. throws SQLException;
  218. /**
  219. * This method sets the specified parameter from the given Java
  220. * binary <code>InputStream</code> value.
  221. *
  222. * @param index The index of the parameter value to set.
  223. * @param stream The stream from which the parameter value is read.
  224. * @param count The number of bytes in the stream.
  225. * @exception SQLException If an error occurs.
  226. */
  227. void setBinaryStream(int index, InputStream stream, int count)
  228. throws SQLException;
  229. /**
  230. * This method clears all of the input parameter that have been
  231. * set on this statement.
  232. *
  233. * @exception SQLException If an error occurs.
  234. */
  235. void clearParameters() throws SQLException;
  236. /**
  237. * This method sets the specified parameter from the given Java
  238. * <code>Object</code> value. The specified SQL object type will be used.
  239. *
  240. * @param index The index of the parameter value to set.
  241. * @param value The value of the parameter.
  242. * @param sqlType The SQL type to use for the parameter, from
  243. * <code>Types</code>
  244. * @param scale The scale of the value, for numeric values only.
  245. * @exception SQLException If an error occurs.
  246. * @see Types
  247. */
  248. void setObject(int index, Object value, int sqlType, int scale)
  249. throws SQLException;
  250. /**
  251. * This method sets the specified parameter from the given Java
  252. * <code>Object</code> value. The specified SQL object type will be used.
  253. *
  254. * @param index The index of the parameter value to set.
  255. * @param value The value of the parameter.
  256. * @param sqlType The SQL type to use for the parameter, from
  257. * <code>Types</code>
  258. * @exception SQLException If an error occurs.
  259. * @see Types
  260. */
  261. void setObject(int index, Object value, int sqlType)
  262. throws SQLException;
  263. /**
  264. * This method sets the specified parameter from the given Java
  265. * <code>Object</code> value. The default object type to SQL type mapping
  266. * will be used.
  267. *
  268. * @param index The index of the parameter value to set.
  269. * @param value The value of the parameter.
  270. * @exception SQLException If an error occurs.
  271. */
  272. void setObject(int index, Object value) throws SQLException;
  273. /**
  274. * This method executes a prepared SQL query.
  275. * Some prepared statements return multiple results; the execute method
  276. * handles these complex statements as well as the simpler form of
  277. * statements handled by executeQuery and executeUpdate.
  278. *
  279. * @return The result of the SQL statement.
  280. * @exception SQLException If an error occurs.
  281. */
  282. boolean execute() throws SQLException;
  283. /**
  284. * This method adds a set of parameters to the batch for JDBC 2.0.
  285. * @exception SQLException If an error occurs.
  286. */
  287. void addBatch() throws SQLException;
  288. /**
  289. * This method sets the specified parameter from the given Java
  290. * character <code>Reader</code> value.
  291. *
  292. * @param index The index of the parameter value to set.
  293. * @param reader The reader from which the parameter value is read.
  294. * @param count The number of characters in the stream.
  295. * @exception SQLException If an error occurs.
  296. */
  297. void setCharacterStream(int index, Reader reader, int count)
  298. throws SQLException;
  299. /**
  300. * This method sets the specified parameter from the given Java
  301. * <code>Ref</code> value. The default object type to SQL type mapping
  302. * will be used.
  303. *
  304. * @param index The index of the parameter value to set.
  305. * @param value The <code>Ref</code> used to set the value of the parameter.
  306. * @exception SQLException If an error occurs.
  307. */
  308. void setRef(int index, Ref value) throws SQLException;
  309. /**
  310. * This method sets the specified parameter from the given Java
  311. * <code>Blob</code> value. The default object type to SQL type mapping
  312. * will be used.
  313. *
  314. * @param index The index of the parameter value to set.
  315. * @param value The <code>Blob</code> used to set the
  316. * value of the parameter.
  317. * @exception SQLException If an error occurs.
  318. */
  319. void setBlob(int index, Blob value) throws SQLException;
  320. /**
  321. * This method sets the specified parameter from the given Java
  322. * <code>Clob</code> value. The default object type to SQL type mapping
  323. * will be used.
  324. *
  325. * @param index The index of the parameter value to set.
  326. * @param value The <code>Clob</code> used to set the
  327. * value of the parameter.
  328. * @exception SQLException If an error occurs.
  329. */
  330. void setClob(int index, Clob value) throws SQLException;
  331. /**
  332. * This method sets the specified parameter from the given Java
  333. * <code>Array</code> value. The default object type to SQL type mapping
  334. * will be used.
  335. *
  336. * @param index The index of the parameter value to set.
  337. * @param value The value of the parameter.
  338. * @exception SQLException If an error occurs.
  339. */
  340. void setArray(int index, Array value) throws SQLException;
  341. /**
  342. * This method returns meta data for the result set from this statement.
  343. *
  344. * @return Meta data for the result set from this statement.
  345. * @exception SQLException If an error occurs.
  346. */
  347. ResultSetMetaData getMetaData() throws SQLException;
  348. /**
  349. * This method sets the specified parameter from the given Java
  350. * <code>java.sql.Date</code> value.
  351. *
  352. * @param index The index of the parameter value to set.
  353. * @param value The value of the parameter.
  354. * @param cal The <code>Calendar</code> to use for timezone and locale.
  355. * @exception SQLException If an error occurs.
  356. */
  357. void setDate(int index, Date value, Calendar cal)
  358. throws SQLException;
  359. /**
  360. * This method sets the specified parameter from the given Java
  361. * <code>java.sql.Time</code> value.
  362. *
  363. * @param index The index of the parameter value to set.
  364. * @param value The value of the parameter.
  365. * @param cal The <code>Calendar</code> to use for timezone and locale.
  366. * @exception SQLException If an error occurs.
  367. */
  368. void setTime(int index, Time value, Calendar cal)
  369. throws SQLException;
  370. /**
  371. * This method sets the specified parameter from the given Java
  372. * <code>java.sql.Timestamp</code> value.
  373. *
  374. * @param index The index of the parameter value to set.
  375. * @param value The value of the parameter.
  376. * @param cal The <code>Calendar</code> to use for timezone and locale.
  377. * @exception SQLException If an error occurs.
  378. */
  379. void setTimestamp(int index, Timestamp value, Calendar cal)
  380. throws SQLException;
  381. /**
  382. * This method populates the specified parameter with a SQL NULL value
  383. * for the specified type.
  384. *
  385. * @param index The index of the parameter to set.
  386. * @param sqlType The SQL type identifier of the parameter from
  387. * <code>Types</code>
  388. * @param typeName The name of the data type, for user defined types.
  389. * @exception SQLException If an error occurs.
  390. */
  391. void setNull(int index, int sqlType, String typeName)
  392. throws SQLException;
  393. /**
  394. * This method sets the specified parameter from the given Java
  395. * <code>java.net.URL</code> value.
  396. *
  397. * @param index The index of the parameter to set.
  398. * @param value The value of the parameter.
  399. * @exception SQLException If an error occurs.
  400. * @since 1.4
  401. */
  402. void setURL(int index, URL value) throws SQLException;
  403. /**
  404. * Returns information about the parameters set on this
  405. * <code>PreparedStatement</code> (see {@link ParameterMetaData} for a
  406. * detailed description of the provided information).
  407. *
  408. * @return Meta data for the parameters of this statement.
  409. * @see ParameterMetaData
  410. * @since 1.4
  411. */
  412. ParameterMetaData getParameterMetaData() throws SQLException;
  413. }