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