1. /*
  2. * @(#)CallableStatement.java 1.29 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.sql;
  11. import java.math.BigDecimal;
  12. import java.util.Calendar;
  13. /**
  14. * The interface used to execute SQL
  15. * stored procedures. JDBC provides a stored procedure
  16. * SQL escape syntax that allows stored procedures to be called in a standard
  17. * way for all RDBMSs. This escape syntax has one form that includes
  18. * a result parameter and one that does not. If used, the result
  19. * parameter must be registered as an OUT parameter. The other parameters
  20. * can be used for input, output or both. Parameters are referred to
  21. * sequentially, by number, with the first parameter being 1.
  22. * <P>
  23. * <blockquote><pre>
  24. * {?= call <procedure-name>[<arg1>,<arg2>, ...]}
  25. * {call <procedure-name>[<arg1>,<arg2>, ...]}
  26. * </pre></blockquote>
  27. * <P>
  28. * IN parameter values are set using the set methods inherited from
  29. * {@link PreparedStatement}. The type of all OUT parameters must be
  30. * registered prior to executing the stored procedure; their values
  31. * are retrieved after execution via the <code>get</code> methods provided here.
  32. * <P>
  33. * A <code>CallableStatement</code> can return one {@link ResultSet} or
  34. * multiple <code>ResultSet</code> objects. Multiple
  35. * <code>ResultSet</code> objects are handled using operations
  36. * inherited from {@link Statement}.
  37. * <P>
  38. * For maximum portability, a call's <code>ResultSet</code> objects and
  39. * update counts should be processed prior to getting the values of output
  40. * parameters.
  41. * <P>
  42. * Methods that are new in the JDBC 2.0 API are marked "Since 1.2."
  43. *
  44. * @see Connection#prepareCall
  45. * @see ResultSet
  46. */
  47. public interface CallableStatement extends PreparedStatement {
  48. /**
  49. * Registers the OUT parameter in ordinal position
  50. * <code>parameterIndex</code> to the JDBC type
  51. * <code>sqlType</code>. All OUT parameters must be registered
  52. * before a stored procedure is executed.
  53. * <p>
  54. * The JDBC type specified by <code>sqlType</code> for an OUT
  55. * parameter determines the Java type that must be used
  56. * in the <code>get</code> method to read the value of that parameter.
  57. * <p>
  58. * If the JDBC type expected to be returned to this output parameter
  59. * is specific to this particular database, <code>sqlType</code>
  60. * should be <code>java.sql.Types.OTHER</code>. The method
  61. * {@link #getObject} retrieves the value.
  62. * @param parameterIndex the first parameter is 1, the second is 2,
  63. * and so on
  64. * @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
  65. * If the parameter is of JDBC type <code>NUMERIC</code>
  66. * or <code>DECIMAL</code>, the version of
  67. * <code>registerOutParameter</code> that accepts a scale value
  68. * should be used.
  69. * @exception SQLException if a database access error occurs
  70. * @see Types
  71. */
  72. void registerOutParameter(int parameterIndex, int sqlType)
  73. throws SQLException;
  74. /**
  75. * Registers the parameter in ordinal position
  76. * <code>parameterIndex</code> to be of JDBC type
  77. * <code>sqlType</code>. This method must be called
  78. * before a stored procedure is executed.
  79. * <p>
  80. * The JDBC type specified by <code>sqlType</code> for an OUT
  81. * parameter determines the Java type that must be used
  82. * in the <code>get</code> method to read the value of that parameter.
  83. * <p>
  84. * This version of <code>registerOutParameter</code> should be
  85. * used when the parameter is of JDBC type <code>NUMERIC</code>
  86. * or <code>DECIMAL</code>.
  87. * @param parameterIndex the first parameter is 1, the second is 2,
  88. * and so on
  89. * @param sqlType SQL type code defined by <code>java.sql.Types</code>.
  90. * @param scale the desired number of digits to the right of the
  91. * decimal point. It must be greater than or equal to zero.
  92. * @exception SQLException if a database access error occurs
  93. * @see Types
  94. */
  95. void registerOutParameter(int parameterIndex, int sqlType, int scale)
  96. throws SQLException;
  97. /**
  98. * Indicates whether or not the last OUT parameter read had the value of
  99. * SQL <code>NULL</code>. Note that this method should be called only after
  100. * calling a <code>getXXX</code> method; otherwise, there is no value to use in
  101. * determining whether it is <code>null</code> or not.
  102. * @return <code>true</code> if the last parameter read was SQL
  103. * <code>NULL</code> <code>false</code> otherwise
  104. * @exception SQLException if a database access error occurs
  105. */
  106. boolean wasNull() throws SQLException;
  107. /**
  108. * Retrieves the value of a JDBC <code>CHAR</code>, <code>VARCHAR</code>,
  109. * or <code>LONGVARCHAR</code> parameter as a <code>String</code> in
  110. * the Java programming language.
  111. * <p>
  112. * For the fixed-length type JDBC <code>CHAR</code>,
  113. * the <code>String</code> object
  114. * returned has exactly the same value the JDBC
  115. * <code>CHAR</code> value had in the
  116. * database, including any padding added by the database.
  117. * @param parameterIndex the first parameter is 1, the second is 2,
  118. * and so on
  119. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  120. * is <code>null</code>.
  121. * @exception SQLException if a database access error occurs
  122. */
  123. String getString(int parameterIndex) throws SQLException;
  124. /**
  125. * Gets the value of a JDBC <code>BIT</code> parameter as a <code>boolean</code>
  126. * in the Java programming language.
  127. * @param parameterIndex the first parameter is 1, the second is 2,
  128. * and so on
  129. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  130. * is <code>false</code>.
  131. * @exception SQLException if a database access error occurs
  132. */
  133. boolean getBoolean(int parameterIndex) throws SQLException;
  134. /**
  135. * Gets the value of a JDBC <code>TINYINT</code> parameter as a <code>byte</code>
  136. * in the Java programming language.
  137. * @param parameterIndex the first parameter is 1, the second is 2,
  138. * and so on
  139. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  140. * is 0.
  141. * @exception SQLException if a database access error occurs
  142. */
  143. byte getByte(int parameterIndex) throws SQLException;
  144. /**
  145. * Gets the value of a JDBC <code>SMALLINT</code> parameter as a <code>short</code>
  146. * in the Java programming language.
  147. * @param parameterIndex the first parameter is 1, the second is 2,
  148. * and so on
  149. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  150. * is 0.
  151. * @exception SQLException if a database access error occurs
  152. */
  153. short getShort(int parameterIndex) throws SQLException;
  154. /**
  155. * Gets the value of a JDBC <code>INTEGER</code> parameter as an <code>int</code>
  156. * in the Java programming language.
  157. * @param parameterIndex the first parameter is 1, the second is 2,
  158. * and so on
  159. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  160. * is 0.
  161. * @exception SQLException if a database access error occurs
  162. */
  163. int getInt(int parameterIndex) throws SQLException;
  164. /**
  165. * Gets the value of a JDBC <code>BIGINT</code> parameter as a <code>long</code>
  166. * in the Java programming language.
  167. * @param parameterIndex the first parameter is 1, the second is 2,
  168. * and so on
  169. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  170. * is 0.
  171. * @exception SQLException if a database access error occurs
  172. */
  173. long getLong(int parameterIndex) throws SQLException;
  174. /**
  175. * Gets the value of a JDBC <code>FLOAT</code> parameter as a <code>float</code>
  176. * in the Java programming language.
  177. * @param parameterIndex the first parameter is 1, the second is 2,
  178. * and so on
  179. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  180. * is 0.
  181. * @exception SQLException if a database access error occurs
  182. */
  183. float getFloat(int parameterIndex) throws SQLException;
  184. /**
  185. * Gets the value of a JDBC <code>DOUBLE</code> parameter as a <code>double</code>
  186. * in the Java programming language.
  187. * @param parameterIndex the first parameter is 1, the second is 2,
  188. * and so on
  189. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  190. * is 0.
  191. * @exception SQLException if a database access error occurs
  192. */
  193. double getDouble(int parameterIndex) throws SQLException;
  194. /**
  195. * Gets the value of a JDBC <code>NUMERIC</code> parameter as a
  196. * <code>java.math.BigDecimal</code> object with scale digits to
  197. * the right of the decimal point.
  198. * @param parameterIndex the first parameter is 1, the second is 2,
  199. * and so on
  200. * @param scale the number of digits to the right of the decimal point
  201. * @return the parameter value. If the value is SQL <code>NULL</code>, the result is
  202. * <code>null</code>.
  203. * @exception SQLException if a database access error occurs
  204. * @deprecated
  205. */
  206. BigDecimal getBigDecimal(int parameterIndex, int scale)
  207. throws SQLException;
  208. /**
  209. * Gets the value of a JDBC <code>BINARY</code> or <code>VARBINARY</code>
  210. * parameter as an array of <code>byte</code> values in the Java
  211. * programming language.
  212. * @param parameterIndex the first parameter is 1, the second is 2,
  213. * and so on
  214. * @return the parameter value. If the value is SQL <code>NULL</code>, the result is
  215. * <code>null</code>.
  216. * @exception SQLException if a database access error occurs
  217. */
  218. byte[] getBytes(int parameterIndex) throws SQLException;
  219. /**
  220. * Gets the value of a JDBC <code>DATE</code> parameter as a
  221. * <code>java.sql.Date</code> object.
  222. * @param parameterIndex the first parameter is 1, the second is 2,
  223. * and so on
  224. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  225. * is <code>null</code>.
  226. * @exception SQLException if a database access error occurs
  227. */
  228. java.sql.Date getDate(int parameterIndex) throws SQLException;
  229. /**
  230. * Get the value of a JDBC <code>TIME</code> parameter as a
  231. * <code>java.sql.Time</code> object.
  232. * @param parameterIndex the first parameter is 1, the second is 2,
  233. * and so on
  234. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  235. * is <code>null</code>.
  236. * @exception SQLException if a database access error occurs
  237. */
  238. java.sql.Time getTime(int parameterIndex) throws SQLException;
  239. /**
  240. * Gets the value of a JDBC <code>TIMESTAMP</code> parameter as a
  241. * <code>java.sql.Timestamp</code> object.
  242. * @param parameterIndex the first parameter is 1, the second is 2,
  243. * and so on
  244. * @return the parameter value. If the value is SQL <code>NULL</code>, the result
  245. * is <code>null</code>.
  246. * @exception SQLException if a database access error occurs
  247. */
  248. java.sql.Timestamp getTimestamp(int parameterIndex)
  249. throws SQLException;
  250. //----------------------------------------------------------------------
  251. // Advanced features:
  252. /**
  253. * Gets the value of a parameter as an <code>Object</code> in the Java
  254. * programming language.
  255. * <p>
  256. * This method returns a Java object whose type corresponds to the JDBC
  257. * type that was registered for this parameter using the method
  258. * <code>registerOutParameter</code>. By registering the target JDBC
  259. * type as <code>java.sql.Types.OTHER</code>, this method can be used
  260. * to read database-specific abstract data types.
  261. * @param parameterIndex the first parameter is 1, the second is 2,
  262. * and so on
  263. * @return A <code>java.lang.Object</code> holding the OUT parameter value.
  264. * @exception SQLException if a database access error occurs
  265. * @see Types
  266. */
  267. Object getObject(int parameterIndex) throws SQLException;
  268. //--------------------------JDBC 2.0-----------------------------
  269. /**
  270. *
  271. * Gets the value of a JDBC <code>NUMERIC</code> parameter as a
  272. * <code>java.math.BigDecimal</code> object with as many digits to the
  273. * right of the decimal point as the value contains.
  274. * @param parameterIndex the first parameter is 1, the second is 2,
  275. * and so on
  276. * @return the parameter value in full precision. If the value is
  277. * SQL <code>NULL</code>, the result is <code>null</code>.
  278. * @exception SQLException if a database access error occurs
  279. * @since 1.2
  280. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  281. */
  282. BigDecimal getBigDecimal(int parameterIndex) throws SQLException;
  283. /**
  284. *
  285. * Returns an object representing the value of OUT parameter
  286. * <code>i</code> and uses <code>map</code> for the custom
  287. * mapping of the parameter value.
  288. * <p>
  289. * This method returns a Java object whose type corresponds to the
  290. * JDBC type that was registered for this parameter using the method
  291. * <code>registerOutParameter</code>. By registering the target
  292. * JDBC type as <code>java.sql.Types.OTHER</code>, this method can
  293. * be used to read database-specific abstract data types.
  294. * @param i the first parameter is 1, the second is 2, and so on
  295. * @param map the mapping from SQL type names to Java classes
  296. * @return a <code>java.lang.Object</code> holding the OUT parameter value
  297. * @exception SQLException if a database access error occurs
  298. * @since 1.2
  299. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  300. */
  301. Object getObject (int i, java.util.Map map) throws SQLException;
  302. /**
  303. *
  304. * Gets the value of a JDBC <code>REF(<structured-type>)</code>
  305. * parameter as a {@link Ref} object in the Java programming language.
  306. * @param i the first parameter is 1, the second is 2,
  307. * and so on
  308. * @return the parameter value as a <code>Ref</code> object in the
  309. * Java programming language. If the value was SQL <code>NULL</code>, the value
  310. * <code>null</code> is returned.
  311. * @exception SQLException if a database access error occurs
  312. * @since 1.2
  313. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  314. */
  315. Ref getRef (int i) throws SQLException;
  316. /**
  317. *
  318. * Gets the value of a JDBC <code>BLOB</code> parameter as a
  319. * {@link Blob} object in the Java programming language.
  320. * @param i the first parameter is 1, the second is 2, and so on
  321. * @return the parameter value as a <code>Blob</code> object in the
  322. * Java programming language. If the value was SQL <code>NULL</code>, the value
  323. * <code>null</code> is returned.
  324. * @exception SQLException if a database access error occurs
  325. * @since 1.2
  326. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  327. */
  328. Blob getBlob (int i) throws SQLException;
  329. /**
  330. *
  331. * Gets the value of a JDBC <code>CLOB</code> parameter as a
  332. * <code>Clob</code> object in the Java programming language.
  333. * @param i the first parameter is 1, the second is 2, and
  334. * so on
  335. * @return the parameter value as a <code>Clob</code> object in the
  336. * Java programming language. If the value was SQL <code>NULL</code>, the
  337. * value <code>null</code> is returned.
  338. * @exception SQLException if a database access error occurs
  339. * @since 1.2
  340. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  341. */
  342. Clob getClob (int i) throws SQLException;
  343. /**
  344. *
  345. * Gets the value of a JDBC <code>ARRAY</code> parameter as an
  346. * {@link Array} object in the Java programming language.
  347. * @param i the first parameter is 1, the second is 2, and
  348. * so on
  349. * @return the parameter value as an <code>Array</code> object in
  350. * the Java programming language. If the value was SQL <code>NULL</code>, the
  351. * value <code>null</code> is returned.
  352. * @exception SQLException if a database access error occurs
  353. * @since 1.2
  354. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  355. */
  356. Array getArray (int i) throws SQLException;
  357. /**
  358. * Gets the value of a JDBC <code>DATE</code> parameter as a
  359. * <code>java.sql.Date</code> object, using
  360. * the given <code>Calendar</code> object
  361. * to construct the date.
  362. * With a <code>Calendar</code> object, the driver
  363. * can calculate the date taking into account a custom timezone and locale.
  364. * If no <code>Calendar</code> object is specified, the driver uses the
  365. * default timezone and locale.
  366. *
  367. * @param parameterIndex the first parameter is 1, the second is 2,
  368. * and so on
  369. * @param cal the <code>Calendar</code> object the driver will use
  370. * to construct the date
  371. * @return the parameter value. If the value is SQL <code>NULL</code>, the result is
  372. * <code>null</code>.
  373. * @exception SQLException if a database access error occurs
  374. */
  375. java.sql.Date getDate(int parameterIndex, Calendar cal)
  376. throws SQLException;
  377. /**
  378. * Gets the value of a JDBC <code>TIME</code> parameter as a
  379. * <code>java.sql.Time</code> object, using
  380. * the given <code>Calendar</code> object
  381. * to construct the time.
  382. * With a <code>Calendar</code> object, the driver
  383. * can calculate the time taking into account a custom timezone and locale.
  384. * If no <code>Calendar</code> object is specified, the driver uses the
  385. * default timezone and locale.
  386. *
  387. * @param parameterIndex the first parameter is 1, the second is 2,
  388. * and so on
  389. * @param cal the <code>Calendar</code> object the driver will use
  390. * to construct the time
  391. * @return the parameter value; if the value is SQL <code>NULL</code>, the result is
  392. * <code>null</code>.
  393. * @exception SQLException if a database access error occurs
  394. */
  395. java.sql.Time getTime(int parameterIndex, Calendar cal)
  396. throws SQLException;
  397. /**
  398. * Gets the value of a JDBC <code>TIMESTAMP</code> parameter as a
  399. * <code>java.sql.Timestamp</code> object, using
  400. * the given <code>Calendar</code> object to construct
  401. * the <code>Timestamp</code> object.
  402. * With a <code>Calendar</code> object, the driver
  403. * can calculate the timestamp taking into account a custom timezone and locale.
  404. * If no <code>Calendar</code> object is specified, the driver uses the
  405. * default timezone and locale.
  406. *
  407. *
  408. * @param parameterIndex the first parameter is 1, the second is 2,
  409. * and so on
  410. * @param cal the <code>Calendar</code> object the driver will use
  411. * to construct the timestamp
  412. * @return the parameter value. If the value is SQL <code>NULL</code>, the result is
  413. * <code>null</code>.
  414. * @exception SQLException if a database access error occurs
  415. */
  416. java.sql.Timestamp getTimestamp(int parameterIndex, Calendar cal)
  417. throws SQLException;
  418. /**
  419. *
  420. * Registers the designated output parameter. This version of
  421. * the method <code>registerOutParameter</code>
  422. * should be used for a user-named or REF output parameter. Examples
  423. * of user-named types include: STRUCT, DISTINCT, JAVA_OBJECT, and
  424. * named array types.
  425. *
  426. * Before executing a stored procedure call, you must explicitly
  427. * call <code>registerOutParameter</code> to register the type from
  428. * <code>java.sql.Types</code> for each
  429. * OUT parameter. For a user-named parameter the fully-qualified SQL
  430. * type name of the parameter should also be given, while a REF
  431. * parameter requires that the fully-qualified type name of the
  432. * referenced type be given. A JDBC driver that does not need the
  433. * type code and type name information may ignore it. To be portable,
  434. * however, applications should always provide these values for
  435. * user-named and REF parameters.
  436. *
  437. * Although it is intended for user-named and REF parameters,
  438. * this method may be used to register a parameter of any JDBC type.
  439. * If the parameter does not have a user-named or REF type, the
  440. * typeName parameter is ignored.
  441. *
  442. * <P><B>Note:</B> When reading the value of an out parameter, you
  443. * must use the <code>getXXX</code> method whose Java type XXX corresponds to the
  444. * parameter's registered SQL type.
  445. *
  446. * @param parameterIndex the first parameter is 1, the second is 2,...
  447. * @param sqlType a value from {@link java.sql.Types}
  448. * @param typeName the fully-qualified name of an SQL structured type
  449. * @exception SQLException if a database access error occurs
  450. * @see Types
  451. * @since 1.2
  452. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  453. */
  454. void registerOutParameter (int paramIndex, int sqlType, String typeName)
  455. throws SQLException;
  456. }