1. /*
  2. * @(#)Connection.java 1.41 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * <P>A connection (session) with a specific
  10. * database. SQL statements are executed and results are returned
  11. * within the context of a connection.
  12. * <P>
  13. * A <code>Connection</code> object's database is able to provide information
  14. * describing its tables, its supported SQL grammar, its stored
  15. * procedures, the capabilities of this connection, and so on. This
  16. * information is obtained with the <code>getMetaData</code> method.
  17. *
  18. * <P><B>Note:</B> By default a <code>Connection</code> object is in
  19. * auto-commit mode, which means that it automatically commits changes
  20. * after executing each statement. If auto-commit mode has been
  21. * disabled, the method <code>commit</code> must be called explicitly in
  22. * order to commit changes; otherwise, database changes will not be saved.
  23. * <P>
  24. * A new <code>Connection</code> object created using the JDBC 2.1 core API
  25. * has an initially empty type map associated with it. A user may enter a
  26. * custom mapping for a UDT in this type map.
  27. * When a UDT is retrieved from a data source with the
  28. * method <code>ResultSet.getObject</code>, the <code>getObject</code> method
  29. * will check the connection's type map to see if there is an entry for that
  30. * UDT. If so, the <code>getObject</code> method will map the UDT to the
  31. * class indicated. If there is no entry, the UDT will be mapped using the
  32. * standard mapping.
  33. * <p>
  34. * A user may create a new type map, which is a <code>java.util.Map</code>
  35. * object, make an entry in it, and pass it to the <code>java.sql</code>
  36. * methods that can perform custom mapping. In this case, the method
  37. * will use the given type map instead of the one associated with
  38. * the connection.
  39. * <p>
  40. * For example, the following code fragment specifies that the SQL
  41. * type <code>ATHLETES</code> will be mapped to the class
  42. * <code>Athletes</code> in the Java programming language.
  43. * The code fragment retrieves the type map for the <code>Connection
  44. * </code> object <code>con</code>, inserts the entry into it, and then sets
  45. * the type map with the new entry as the connection's type map.
  46. * <pre>
  47. * java.util.Map map = con.getTypeMap();
  48. * map.put("mySchemaName.ATHLETES", Class.forName("Athletes"));
  49. * con.setTypeMap(map);
  50. * </pre>
  51. *
  52. * @see DriverManager#getConnection
  53. * @see Statement
  54. * @see ResultSet
  55. * @see DatabaseMetaData
  56. */
  57. public interface Connection {
  58. /**
  59. * Creates a <code>Statement</code> object for sending
  60. * SQL statements to the database.
  61. * SQL statements without parameters are normally
  62. * executed using <code>Statement</code> objects. If the same SQL statement
  63. * is executed many times, it may be more efficient to use a
  64. * <code>PreparedStatement</code> object.
  65. * <P>
  66. * Result sets created using the returned <code>Statement</code>
  67. * object will by default be type <code>TYPE_FORWARD_ONLY</code>
  68. * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
  69. *
  70. * @return a new default <code>Statement</code> object
  71. * @exception SQLException if a database access error occurs
  72. */
  73. Statement createStatement() throws SQLException;
  74. /**
  75. * Creates a <code>PreparedStatement</code> object for sending
  76. * parameterized SQL statements to the database.
  77. * <P>
  78. * A SQL statement with or without IN parameters can be
  79. * pre-compiled and stored in a <code>PreparedStatement</code> object. This
  80. * object can then be used to efficiently execute this statement
  81. * multiple times.
  82. *
  83. * <P><B>Note:</B> This method is optimized for handling
  84. * parametric SQL statements that benefit from precompilation. If
  85. * the driver supports precompilation,
  86. * the method <code>prepareStatement</code> will send
  87. * the statement to the database for precompilation. Some drivers
  88. * may not support precompilation. In this case, the statement may
  89. * not be sent to the database until the <code>PreparedStatement</code>
  90. * object is executed. This has no direct effect on users; however, it does
  91. * affect which methods throw certain <code>SQLException</code> objects.
  92. * <P>
  93. * Result sets created using the returned <code>PreparedStatement</code>
  94. * object will by default be type <code>TYPE_FORWARD_ONLY</code>
  95. * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
  96. *
  97. * @param sql an SQL statement that may contain one or more '?' IN
  98. * parameter placeholders
  99. * @return a new default <code>PreparedStatement</code> object containing the
  100. * pre-compiled SQL statement
  101. * @exception SQLException if a database access error occurs
  102. */
  103. PreparedStatement prepareStatement(String sql)
  104. throws SQLException;
  105. /**
  106. * Creates a <code>CallableStatement</code> object for calling
  107. * database stored procedures.
  108. * The <code>CallableStatement</code> object provides
  109. * methods for setting up its IN and OUT parameters, and
  110. * methods for executing the call to a stored procedure.
  111. *
  112. * <P><B>Note:</B> This method is optimized for handling stored
  113. * procedure call statements. Some drivers may send the call
  114. * statement to the database when the method <code>prepareCall</code>
  115. * is done; others
  116. * may wait until the <code>CallableStatement</code> object
  117. * is executed. This has no
  118. * direct effect on users; however, it does affect which method
  119. * throws certain SQLExceptions.
  120. * <P>
  121. * Result sets created using the returned <code>CallableStatement</code>
  122. * object will by default be type <code>TYPE_FORWARD_ONLY</code>
  123. * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
  124. *
  125. * @param sql an SQL statement that may contain one or more '?'
  126. * parameter placeholders. Typically this statement is a JDBC
  127. * function call escape string.
  128. * @return a new default <code>CallableStatement</code> object containing the
  129. * pre-compiled SQL statement
  130. * @exception SQLException if a database access error occurs
  131. */
  132. CallableStatement prepareCall(String sql) throws SQLException;
  133. /**
  134. * Converts the given SQL statement into the system's native SQL grammar.
  135. * A driver may convert the JDBC SQL grammar into its system's
  136. * native SQL grammar prior to sending it. This method returns the
  137. * native form of the statement that the driver would have sent.
  138. *
  139. * @param sql an SQL statement that may contain one or more '?'
  140. * parameter placeholders
  141. * @return the native form of this statement
  142. * @exception SQLException if a database access error occurs
  143. */
  144. String nativeSQL(String sql) throws SQLException;
  145. /**
  146. * Sets this connection's auto-commit mode to the given state.
  147. * If a connection is in auto-commit mode, then all its SQL
  148. * statements will be executed and committed as individual
  149. * transactions. Otherwise, its SQL statements are grouped into
  150. * transactions that are terminated by a call to either
  151. * the method <code>commit</code> or the method <code>rollback</code>.
  152. * By default, new connections are in auto-commit
  153. * mode.
  154. * <P>
  155. * The commit occurs when the statement completes or the next
  156. * execute occurs, whichever comes first. In the case of
  157. * statements returning a <code>ResultSet</code> object,
  158. * the statement completes when the last row of the
  159. * <code>ResultSet</code> object has been retrieved or the
  160. * <code>ResultSet</code> object has been closed. In advanced cases, a single
  161. * statement may return multiple results as well as output
  162. * parameter values. In these cases, the commit occurs when all results and
  163. * output parameter values have been retrieved.
  164. * <P>
  165. * <B>NOTE:</B> If this method is called during a transaction, the
  166. * transaction is committed.
  167. *
  168. * @param autoCommit <code>true</code> to enable auto-commit mode;
  169. * <code>false</code> to disable it
  170. * @exception SQLException if a database access error occurs
  171. * @see #getAutoCommit
  172. */
  173. void setAutoCommit(boolean autoCommit) throws SQLException;
  174. /**
  175. * Retrieves the current auto-commit mode for this <code>Connection</code>
  176. * object.
  177. *
  178. * @return the current state of this <code>Connection</code> object's
  179. * auto-commit mode
  180. * @exception SQLException if a database access error occurs
  181. * @see #setAutoCommit
  182. */
  183. boolean getAutoCommit() throws SQLException;
  184. /**
  185. * Makes all changes made since the previous
  186. * commit/rollback permanent and releases any database locks
  187. * currently held by this <code>Connection</code> object.
  188. * This method should be
  189. * used only when auto-commit mode has been disabled.
  190. *
  191. * @exception SQLException if a database access error occurs or this
  192. * <code>Connection</code> object is in auto-commit mode
  193. * @see #setAutoCommit
  194. */
  195. void commit() throws SQLException;
  196. /**
  197. * Undoes all changes made in the current transaction
  198. * and releases any database locks currently held
  199. * by this <code>Connection</code> object. This method should be
  200. * used only when auto-commit mode has been disabled.
  201. *
  202. * @exception SQLException if a database access error occurs or this
  203. * <code>Connection</code> object is in auto-commit mode
  204. * @see #setAutoCommit
  205. */
  206. void rollback() throws SQLException;
  207. /**
  208. * Releases this <code>Connection</code> object's database and JDBC resources
  209. * immediately instead of waiting for them to be automatically released.
  210. * <P>
  211. * Calling the method <code>close</code> on a <code>Connection</code>
  212. * object that is already closed is a no-op.
  213. * <P>
  214. * <B>Note:</B> A <code>Connection</code> object is automatically
  215. * closed when it is garbage collected. Certain fatal errors also
  216. * close a <code>Connection</code> object.
  217. *
  218. * @exception SQLException if a database access error occurs
  219. */
  220. void close() throws SQLException;
  221. /**
  222. * Retrieves whether this <code>Connection</code> object has been
  223. * closed. A connection is closed if the method <code>close</code>
  224. * has been called on it or if certain fatal errors have occurred.
  225. * This method is guaranteed to return <code>true</code> only when
  226. * it is called after the method <code>Connection.close</code> has
  227. * been called.
  228. * <P>
  229. * This method generally cannot be called to determine whether a
  230. * connection to a database is valid or invalid. A typical client
  231. * can determine that a connection is invalid by catching any
  232. * exceptions that might be thrown when an operation is attempted.
  233. *
  234. * @return <code>true</code> if this <code>Connection</code> object
  235. * is closed; <code>false</code> if it is still open
  236. * @exception SQLException if a database access error occurs
  237. */
  238. boolean isClosed() throws SQLException;
  239. //======================================================================
  240. // Advanced features:
  241. /**
  242. * Retrieves a <code>DatabaseMetaData</code> object that contains
  243. * metadata about the database to which this
  244. * <code>Connection</code> object represents a connection.
  245. * The metadata includes information about the database's
  246. * tables, its supported SQL grammar, its stored
  247. * procedures, the capabilities of this connection, and so on.
  248. *
  249. * @return a <code>DatabaseMetaData</code> object for this
  250. * <code>Connection</code> object
  251. * @exception SQLException if a database access error occurs
  252. */
  253. DatabaseMetaData getMetaData() throws SQLException;
  254. /**
  255. * Puts this connection in read-only mode as a hint to the driver to enable
  256. * database optimizations.
  257. *
  258. * <P><B>Note:</B> This method cannot be called during a transaction.
  259. *
  260. * @param readOnly <code>true</code> enables read-only mode;
  261. * <code>false</code> disables it
  262. * @exception SQLException if a database access error occurs or this
  263. * method is called during a transaction
  264. */
  265. void setReadOnly(boolean readOnly) throws SQLException;
  266. /**
  267. * Retrieves whether this <code>Connection</code>
  268. * object is in read-only mode.
  269. *
  270. * @return <code>true</code> if this <code>Connection</code> object
  271. * is read-only; <code>false</code> otherwise
  272. * @exception SQLException if a database access error occurs
  273. */
  274. boolean isReadOnly() throws SQLException;
  275. /**
  276. * Sets the given catalog name in order to select
  277. * a subspace of this <code>Connection</code> object's database
  278. * in which to work.
  279. * <P>
  280. * If the driver does not support catalogs, it will
  281. * silently ignore this request.
  282. *
  283. * @param catalog the name of a catalog (subspace in this
  284. * <code>Connection</code> object's database) in which to work
  285. * @exception SQLException if a database access error occurs
  286. * @see #getCatalog
  287. */
  288. void setCatalog(String catalog) throws SQLException;
  289. /**
  290. * Retrieves this <code>Connection</code> object's current catalog name.
  291. *
  292. * @return the current catalog name or <code>null</code> if there is none
  293. * @exception SQLException if a database access error occurs
  294. * @see #setCatalog
  295. */
  296. String getCatalog() throws SQLException;
  297. /**
  298. * A constant indicating that transactions are not supported.
  299. */
  300. int TRANSACTION_NONE = 0;
  301. /**
  302. * A constant indicating that
  303. * dirty reads, non-repeatable reads and phantom reads can occur.
  304. * This level allows a row changed by one transaction to be read
  305. * by another transaction before any changes in that row have been
  306. * committed (a "dirty read"). If any of the changes are rolled back,
  307. * the second transaction will have retrieved an invalid row.
  308. */
  309. int TRANSACTION_READ_UNCOMMITTED = 1;
  310. /**
  311. * A constant indicating that
  312. * dirty reads are prevented; non-repeatable reads and phantom
  313. * reads can occur. This level only prohibits a transaction
  314. * from reading a row with uncommitted changes in it.
  315. */
  316. int TRANSACTION_READ_COMMITTED = 2;
  317. /**
  318. * A constant indicating that
  319. * dirty reads and non-repeatable reads are prevented; phantom
  320. * reads can occur. This level prohibits a transaction from
  321. * reading a row with uncommitted changes in it, and it also
  322. * prohibits the situation where one transaction reads a row,
  323. * a second transaction alters the row, and the first transaction
  324. * rereads the row, getting different values the second time
  325. * (a "non-repeatable read").
  326. */
  327. int TRANSACTION_REPEATABLE_READ = 4;
  328. /**
  329. * A constant indicating that
  330. * dirty reads, non-repeatable reads and phantom reads are prevented.
  331. * This level includes the prohibitions in
  332. * <code>TRANSACTION_REPEATABLE_READ</code> and further prohibits the
  333. * situation where one transaction reads all rows that satisfy
  334. * a <code>WHERE</code> condition, a second transaction inserts a row that
  335. * satisfies that <code>WHERE</code> condition, and the first transaction
  336. * rereads for the same condition, retrieving the additional
  337. * "phantom" row in the second read.
  338. */
  339. int TRANSACTION_SERIALIZABLE = 8;
  340. /**
  341. * Attempts to change the transaction isolation level for this
  342. * <code>Connection</code> object to the one given.
  343. * The constants defined in the interface <code>Connection</code>
  344. * are the possible transaction isolation levels.
  345. * <P>
  346. * <B>Note:</B> If this method is called during a transaction, the result
  347. * is implementation-defined.
  348. *
  349. * @param level one of the following <code>Connection</code> constants:
  350. * <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
  351. * <code>Connection.TRANSACTION_READ_COMMITTED</code>,
  352. * <code>Connection.TRANSACTION_REPEATABLE_READ</code>, or
  353. * <code>Connection.TRANSACTION_SERIALIZABLE</code>.
  354. * (Note that <code>Connection.TRANSACTION_NONE</code> cannot be used
  355. * because it specifies that transactions are not supported.)
  356. * @exception SQLException if a database access error occurs
  357. * or the given parameter is not one of the <code>Connection</code>
  358. * constants
  359. * @see DatabaseMetaData#supportsTransactionIsolationLevel
  360. * @see #getTransactionIsolation
  361. */
  362. void setTransactionIsolation(int level) throws SQLException;
  363. /**
  364. * Retrieves this <code>Connection</code> object's current
  365. * transaction isolation level.
  366. *
  367. * @return the current transaction isolation level, which will be one
  368. * of the following constants:
  369. * <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
  370. * <code>Connection.TRANSACTION_READ_COMMITTED</code>,
  371. * <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
  372. * <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
  373. * <code>Connection.TRANSACTION_NONE</code>.
  374. * @exception SQLException if a database access error occurs
  375. * @see #setTransactionIsolation
  376. */
  377. int getTransactionIsolation() throws SQLException;
  378. /**
  379. * Retrieves the first warning reported by calls on this
  380. * <code>Connection</code> object. If there is more than one
  381. * warning, subsequent warnings will be chained to the first one
  382. * and can be retrieved by calling the method
  383. * <code>SQLWarning.getNextWarning</code> on the warning
  384. * that was retrieved previously.
  385. * <P>
  386. * This method may not be
  387. * called on a closed connection; doing so will cause an
  388. * <code>SQLException</code> to be thrown.
  389. *
  390. * <P><B>Note:</B> Subsequent warnings will be chained to this
  391. * SQLWarning.
  392. *
  393. * @return the first <code>SQLWarning</code> object or <code>null</code>
  394. * if there are none
  395. * @exception SQLException if a database access error occurs or
  396. * this method is called on a closed connection
  397. * @see SQLWarning
  398. */
  399. SQLWarning getWarnings() throws SQLException;
  400. /**
  401. * Clears all warnings reported for this <code>Connection</code> object.
  402. * After a call to this method, the method <code>getWarnings</code>
  403. * returns <code>null</code> until a new warning is
  404. * reported for this <code>Connection</code> object.
  405. *
  406. * @exception SQLException if a database access error occurs
  407. */
  408. void clearWarnings() throws SQLException;
  409. //--------------------------JDBC 2.0-----------------------------
  410. /**
  411. * Creates a <code>Statement</code> object that will generate
  412. * <code>ResultSet</code> objects with the given type and concurrency.
  413. * This method is the same as the <code>createStatement</code> method
  414. * above, but it allows the default result set
  415. * type and concurrency to be overridden.
  416. *
  417. * @param resultSetType a result set type; one of
  418. * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
  419. * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
  420. * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
  421. * @param resultSetConcurrency a concurrency type; one of
  422. * <code>ResultSet.CONCUR_READ_ONLY</code> or
  423. * <code>ResultSet.CONCUR_UPDATABLE</code>
  424. * @return a new <code>Statement</code> object that will generate
  425. * <code>ResultSet</code> objects with the given type and
  426. * concurrency
  427. * @exception SQLException if a database access error occurs
  428. * or the given parameters are not <code>ResultSet</code>
  429. * constants indicating type and concurrency
  430. * @since 1.2
  431. */
  432. Statement createStatement(int resultSetType, int resultSetConcurrency)
  433. throws SQLException;
  434. /**
  435. *
  436. * Creates a <code>PreparedStatement</code> object that will generate
  437. * <code>ResultSet</code> objects with the given type and concurrency.
  438. * This method is the same as the <code>prepareStatement</code> method
  439. * above, but it allows the default result set
  440. * type and concurrency to be overridden.
  441. *
  442. * @param sql a <code>String</code> object that is the SQL statement to
  443. * be sent to the database; may contain one or more ? IN
  444. * parameters
  445. * @param resultSetType a result set type; one of
  446. * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
  447. * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
  448. * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
  449. * @param resultSetConcurrency a concurrency type; one of
  450. * <code>ResultSet.CONCUR_READ_ONLY</code> or
  451. * <code>ResultSet.CONCUR_UPDATABLE</code>
  452. * @return a new PreparedStatement object containing the
  453. * pre-compiled SQL statement that will produce <code>ResultSet</code>
  454. * objects with the given type and concurrency
  455. * @exception SQLException if a database access error occurs
  456. * or the given parameters are not <code>ResultSet</code>
  457. * constants indicating type and concurrency
  458. * @since 1.2
  459. */
  460. PreparedStatement prepareStatement(String sql, int resultSetType,
  461. int resultSetConcurrency)
  462. throws SQLException;
  463. /**
  464. * Creates a <code>CallableStatement</code> object that will generate
  465. * <code>ResultSet</code> objects with the given type and concurrency.
  466. * This method is the same as the <code>prepareCall</code> method
  467. * above, but it allows the default result set
  468. * type and concurrency to be overridden.
  469. *
  470. * @param sql a <code>String</code> object that is the SQL statement to
  471. * be sent to the database; may contain on or more ? parameters
  472. * @param resultSetType a result set type; one of
  473. * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
  474. * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
  475. * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
  476. * @param resultSetConcurrency a concurrency type; one of
  477. * <code>ResultSet.CONCUR_READ_ONLY</code> or
  478. * <code>ResultSet.CONCUR_UPDATABLE</code>
  479. * @return a new <code>CallableStatement</code> object containing the
  480. * pre-compiled SQL statement that will produce <code>ResultSet</code>
  481. * objects with the given type and concurrency
  482. * @exception SQLException if a database access error occurs
  483. * or the given parameters are not <code>ResultSet</code>
  484. * constants indicating type and concurrency
  485. * @since 1.2
  486. */
  487. CallableStatement prepareCall(String sql, int resultSetType,
  488. int resultSetConcurrency) throws SQLException;
  489. /**
  490. * Retrieves the <code>Map</code> object associated with this
  491. * <code>Connection</code> object.
  492. * Unless the application has added an entry, the type map returned
  493. * will be empty.
  494. *
  495. * @return the <code>java.util.Map</code> object associated
  496. * with this <code>Connection</code> object
  497. * @exception SQLException if a database access error occurs
  498. * @since 1.2
  499. * @see #setTypeMap
  500. */
  501. java.util.Map getTypeMap() throws SQLException;
  502. /**
  503. * Installs the given <code>TypeMap</code> object as the type map for
  504. * this <code>Connection</code> object. The type map will be used for the
  505. * custom mapping of SQL structured types and distinct types.
  506. *
  507. * @param map the <code>java.util.Map</code> object to install
  508. * as the replacement for this <code>Connection</code>
  509. * object's default type map
  510. * @exception SQLException if a database access error occurs or
  511. * the given parameter is not a <code>java.util.Map</code>
  512. * object
  513. * @since 1.2
  514. * @see #getTypeMap
  515. */
  516. void setTypeMap(java.util.Map map) throws SQLException;
  517. //--------------------------JDBC 3.0-----------------------------
  518. /**
  519. * Changes the holdability of <code>ResultSet</code> objects
  520. * created using this <code>Connection</code> object to the given
  521. * holdability.
  522. *
  523. * @param holdability a <code>ResultSet</code> holdability constant; one of
  524. * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
  525. * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
  526. * @throws SQLException if a database access occurs, the given parameter
  527. * is not a <code>ResultSet</code> constant indicating holdability,
  528. * or the given holdability is not supported
  529. * @see #getHoldability
  530. * @see ResultSet
  531. * @since 1.4
  532. */
  533. void setHoldability(int holdability) throws SQLException;
  534. /**
  535. * Retrieves the current holdability of <code>ResultSet</code> objects
  536. * created using this <code>Connection</code> object.
  537. *
  538. * @return the holdability, one of
  539. * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
  540. * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
  541. * @throws SQLException if a database access occurs
  542. * @see #setHoldability
  543. * @see ResultSet
  544. * @since 1.4
  545. */
  546. int getHoldability() throws SQLException;
  547. /**
  548. * Creates an unnamed savepoint in the current transaction and
  549. * returns the new <code>Savepoint</code> object that represents it.
  550. *
  551. * @return the new <code>Savepoint</code> object
  552. * @exception SQLException if a database access error occurs
  553. * or this <code>Connection</code> object is currently in
  554. * auto-commit mode
  555. * @see Savepoint
  556. * @since 1.4
  557. */
  558. Savepoint setSavepoint() throws SQLException;
  559. /**
  560. * Creates a savepoint with the given name in the current transaction
  561. * and returns the new <code>Savepoint</code> object that represents it.
  562. *
  563. * @param name a <code>String</code> containing the name of the savepoint
  564. * @return the new <code>Savepoint</code> object
  565. * @exception SQLException if a database access error occurs
  566. * or this <code>Connection</code> object is currently in
  567. * auto-commit mode
  568. * @see Savepoint
  569. * @since 1.4
  570. */
  571. Savepoint setSavepoint(String name) throws SQLException;
  572. /**
  573. * Undoes all changes made after the given <code>Savepoint</code> object
  574. * was set.
  575. * <P>
  576. * This method should be used only when auto-commit has been disabled.
  577. *
  578. * @param savepoint the <code>Savepoint</code> object to roll back to
  579. * @exception SQLException if a database access error occurs,
  580. * the <code>Savepoint</code> object is no longer valid,
  581. * or this <code>Connection</code> object is currently in
  582. * auto-commit mode
  583. * @see Savepoint
  584. * @see #rollback
  585. * @since 1.4
  586. */
  587. void rollback(Savepoint savepoint) throws SQLException;
  588. /**
  589. * Removes the given <code>Savepoint</code> object from the current
  590. * transaction. Any reference to the savepoint after it have been removed
  591. * will cause an <code>SQLException</code> to be thrown.
  592. *
  593. * @param savepoint the <code>Savepoint</code> object to be removed
  594. * @exception SQLException if a database access error occurs or
  595. * the given <code>Savepoint</code> object is not a valid
  596. * savepoint in the current transaction
  597. * @since 1.4
  598. */
  599. void releaseSavepoint(Savepoint savepoint) throws SQLException;
  600. /**
  601. * Creates a <code>Statement</code> object that will generate
  602. * <code>ResultSet</code> objects with the given type, concurrency,
  603. * and holdability.
  604. * This method is the same as the <code>createStatement</code> method
  605. * above, but it allows the default result set
  606. * type, concurrency, and holdability to be overridden.
  607. *
  608. * @param resultSetType one of the following <code>ResultSet</code>
  609. * constants:
  610. * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
  611. * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
  612. * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
  613. * @param resultSetConcurrency one of the following <code>ResultSet</code>
  614. * constants:
  615. * <code>ResultSet.CONCUR_READ_ONLY</code> or
  616. * <code>ResultSet.CONCUR_UPDATABLE</code>
  617. * @param resultSetHoldability one of the following <code>ResultSet</code>
  618. * constants:
  619. * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
  620. * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
  621. * @return a new <code>Statement</code> object that will generate
  622. * <code>ResultSet</code> objects with the given type,
  623. * concurrency, and holdability
  624. * @exception SQLException if a database access error occurs
  625. * or the given parameters are not <code>ResultSet</code>
  626. * constants indicating type, concurrency, and holdability
  627. * @see ResultSet
  628. * @since 1.4
  629. */
  630. Statement createStatement(int resultSetType, int resultSetConcurrency,
  631. int resultSetHoldability) throws SQLException;
  632. /**
  633. * Creates a <code>PreparedStatement</code> object that will generate
  634. * <code>ResultSet</code> objects with the given type, concurrency,
  635. * and holdability.
  636. * <P>
  637. * This method is the same as the <code>prepareStatement</code> method
  638. * above, but it allows the default result set
  639. * type, concurrency, and holdability to be overridden.
  640. *
  641. * @param sql a <code>String</code> object that is the SQL statement to
  642. * be sent to the database; may contain one or more ? IN
  643. * parameters
  644. * @param resultSetType one of the following <code>ResultSet</code>
  645. * constants:
  646. * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
  647. * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
  648. * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
  649. * @param resultSetConcurrency one of the following <code>ResultSet</code>
  650. * constants:
  651. * <code>ResultSet.CONCUR_READ_ONLY</code> or
  652. * <code>ResultSet.CONCUR_UPDATABLE</code>
  653. * @param resultSetHoldability one of the following <code>ResultSet</code>
  654. * constants:
  655. * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
  656. * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
  657. * @return a new <code>PreparedStatement</code> object, containing the
  658. * pre-compiled SQL statement, that will generate
  659. * <code>ResultSet</code> objects with the given type,
  660. * concurrency, and holdability
  661. * @exception SQLException if a database access error occurs
  662. * or the given parameters are not <code>ResultSet</code>
  663. * constants indicating type, concurrency, and holdability
  664. * @see ResultSet
  665. * @since 1.4
  666. */
  667. PreparedStatement prepareStatement(String sql, int resultSetType,
  668. int resultSetConcurrency, int resultSetHoldability)
  669. throws SQLException;
  670. /**
  671. * Creates a <code>CallableStatement</code> object that will generate
  672. * <code>ResultSet</code> objects with the given type and concurrency.
  673. * This method is the same as the <code>prepareCall</code> method
  674. * above, but it allows the default result set
  675. * type, result set concurrency type and holdability to be overridden.
  676. *
  677. * @param sql a <code>String</code> object that is the SQL statement to
  678. * be sent to the database; may contain on or more ? parameters
  679. * @param resultSetType one of the following <code>ResultSet</code>
  680. * constants:
  681. * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
  682. * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
  683. * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
  684. * @param resultSetConcurrency one of the following <code>ResultSet</code>
  685. * constants:
  686. * <code>ResultSet.CONCUR_READ_ONLY</code> or
  687. * <code>ResultSet.CONCUR_UPDATABLE</code>
  688. * @param resultSetHoldability one of the following <code>ResultSet</code>
  689. * constants:
  690. * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
  691. * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
  692. * @return a new <code>CallableStatement</code> object, containing the
  693. * pre-compiled SQL statement, that will generate
  694. * <code>ResultSet</code> objects with the given type,
  695. * concurrency, and holdability
  696. * @exception SQLException if a database access error occurs
  697. * or the given parameters are not <code>ResultSet</code>
  698. * constants indicating type, concurrency, and holdability
  699. * @see ResultSet
  700. * @since 1.4
  701. */
  702. CallableStatement prepareCall(String sql, int resultSetType,
  703. int resultSetConcurrency,
  704. int resultSetHoldability) throws SQLException;
  705. /**
  706. * Creates a default <code>PreparedStatement</code> object that has
  707. * the capability to retrieve auto-generated keys. The given constant
  708. * tells the driver whether it should make auto-generated keys
  709. * available for retrieval. This parameter is ignored if the SQL
  710. * statement is not an <code>INSERT</code> statement.
  711. * <P>
  712. * <B>Note:</B> This method is optimized for handling
  713. * parametric SQL statements that benefit from precompilation. If
  714. * the driver supports precompilation,
  715. * the method <code>prepareStatement</code> will send
  716. * the statement to the database for precompilation. Some drivers
  717. * may not support precompilation. In this case, the statement may
  718. * not be sent to the database until the <code>PreparedStatement</code>
  719. * object is executed. This has no direct effect on users; however, it does
  720. * affect which methods throw certain SQLExceptions.
  721. * <P>
  722. * Result sets created using the returned <code>PreparedStatement</code>
  723. * object will by default be type <code>TYPE_FORWARD_ONLY</code>
  724. * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
  725. *
  726. * @param sql an SQL statement that may contain one or more '?' IN
  727. * parameter placeholders
  728. * @param autoGeneratedKeys a flag indicating whether auto-generated keys
  729. * should be returned; one of
  730. * <code>Statement.RETURN_GENERATED_KEYS</code> or
  731. * <code>Statement.NO_GENERATED_KEYS</code>
  732. * @return a new <code>PreparedStatement</code> object, containing the
  733. * pre-compiled SQL statement, that will have the capability of
  734. * returning auto-generated keys
  735. * @exception SQLException if a database access error occurs
  736. * or the given parameter is not a <code>Statement</code>
  737. * constant indicating whether auto-generated keys should be
  738. * returned
  739. * @since 1.4
  740. */
  741. PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
  742. throws SQLException;
  743. /**
  744. * Creates a default <code>PreparedStatement</code> object capable
  745. * of returning the auto-generated keys designated by the given array.
  746. * This array contains the indexes of the columns in the target
  747. * table that contain the auto-generated keys that should be made
  748. * available. This array is ignored if the SQL
  749. * statement is not an <code>INSERT</code> statement.
  750. * <P>
  751. * An SQL statement with or without IN parameters can be
  752. * pre-compiled and stored in a <code>PreparedStatement</code> object. This
  753. * object can then be used to efficiently execute this statement
  754. * multiple times.
  755. * <P>
  756. * <B>Note:</B> This method is optimized for handling
  757. * parametric SQL statements that benefit from precompilation. If
  758. * the driver supports precompilation,
  759. * the method <code>prepareStatement</code> will send
  760. * the statement to the database for precompilation. Some drivers
  761. * may not support precompilation. In this case, the statement may
  762. * not be sent to the database until the <code>PreparedStatement</code>
  763. * object is executed. This has no direct effect on users; however, it does
  764. * affect which methods throw certain SQLExceptions.
  765. * <P>
  766. * Result sets created using the returned <code>PreparedStatement</code>
  767. * object will by default be type <code>TYPE_FORWARD_ONLY</code>
  768. * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
  769. *
  770. * @param sql an SQL statement that may contain one or more '?' IN
  771. * parameter placeholders
  772. * @param columnIndexes an array of column indexes indicating the columns
  773. * that should be returned from the inserted row or rows
  774. * @return a new <code>PreparedStatement</code> object, containing the
  775. * pre-compiled statement, that is capable of returning the
  776. * auto-generated keys designated by the given array of column
  777. * indexes
  778. * @exception SQLException if a database access error occurs
  779. *
  780. * @since 1.4
  781. */
  782. PreparedStatement prepareStatement(String sql, int columnIndexes[])
  783. throws SQLException;
  784. /**
  785. * Creates a default <code>PreparedStatement</code> object capable
  786. * of returning the auto-generated keys designated by the given array.
  787. * This array contains the names of the columns in the target
  788. * table that contain the auto-generated keys that should be returned.
  789. * This array is ignored if the SQL
  790. * statement is not an <code>INSERT</code> statement.
  791. * <P>
  792. * An SQL statement with or without IN parameters can be
  793. * pre-compiled and stored in a <code>PreparedStatement</code> object. This
  794. * object can then be used to efficiently execute this statement
  795. * multiple times.
  796. * <P>
  797. * <B>Note:</B> This method is optimized for handling
  798. * parametric SQL statements that benefit from precompilation. If
  799. * the driver supports precompilation,
  800. * the method <code>prepareStatement</code> will send
  801. * the statement to the database for precompilation. Some drivers
  802. * may not support precompilation. In this case, the statement may
  803. * not be sent to the database until the <code>PreparedStatement</code>
  804. * object is executed. This has no direct effect on users; however, it does
  805. * affect which methods throw certain SQLExceptions.
  806. * <P>
  807. * Result sets created using the returned <code>PreparedStatement</code>
  808. * object will by default be type <code>TYPE_FORWARD_ONLY</code>
  809. * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
  810. *
  811. * @param sql an SQL statement that may contain one or more '?' IN
  812. * parameter placeholders
  813. * @param columnNames an array of column names indicating the columns
  814. * that should be returned from the inserted row or rows
  815. * @return a new <code>PreparedStatement</code> object, containing the
  816. * pre-compiled statement, that is capable of returning the
  817. * auto-generated keys designated by the given array of column
  818. * names
  819. * @exception SQLException if a database access error occurs
  820. *
  821. * @since 1.4
  822. */
  823. PreparedStatement prepareStatement(String sql, String columnNames[])
  824. throws SQLException;
  825. }