Import GNU Classpath (20121202).
[official-gcc.git] / libjava / classpath / java / sql / Connection.java
blobb1e7034b5a316709842a3a0f6841df70f8d99927
1 /* Connection.java -- Manage a database connection.
2 Copyright (C) 1999, 2000, 2002, 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.sql;
41 import java.util.Map;
43 /**
44 * This interface provides methods for managing a connection to a database.
46 * @author Aaron M. Renn (arenn@urbanophile.com)
48 public interface Connection
49 extends AutoCloseable
51 /**
52 * This transaction isolation level indicates that transactions are not
53 * supported.
55 int TRANSACTION_NONE = 0;
57 /**
58 * This transaction isolation level indicates that one transaction can
59 * read modifications by other transactions before the other transactions
60 * have committed their changes. This could result in invalid reads.
62 int TRANSACTION_READ_UNCOMMITTED = 1;
64 /**
65 * This transaction isolation level indicates that only committed data from
66 * other transactions will be read. If a transaction reads a row, then
67 * another transaction commits a change to that row, the first transaction
68 * would retrieve the changed row on subsequent reads of the same row.
70 int TRANSACTION_READ_COMMITTED = 2;
72 /**
73 * This transaction isolation level indicates that only committed data from
74 * other transactions will be read. It also ensures that data read from
75 * a row will not be different on a subsequent read even if another
76 * transaction commits a change.
78 int TRANSACTION_REPEATABLE_READ = 4;
80 /**
81 * This transaction isolation level indicates that only committed data from
82 * other transactions will be read. It also ensures that data read from
83 * a row will not be different on a subsequent read even if another
84 * transaction commits a change. Additionally, rows modified by other
85 * transactions will not affect the result set returned during subsequent
86 * executions of the same WHERE clause in this transaction.
88 int TRANSACTION_SERIALIZABLE = 8;
90 /**
91 * This method creates a new SQL statement. The default result set type
92 * and concurrency will be used.
94 * @return A new <code>Statement</code> object.
95 * @exception SQLException If an error occurs.
96 * @see Statement
98 Statement createStatement() throws SQLException;
101 * This method creates a new <code>PreparedStatement</code> for the specified
102 * SQL string. This method is designed for use with parameterized
103 * statements. The default result set type and concurrency will be used.
105 * @param sql The SQL statement to use in creating this
106 * <code>PreparedStatement</code>.
107 * @return A new <code>PreparedStatement</code>.
108 * @exception SQLException If an error occurs.
109 * @see PreparedStatement
111 PreparedStatement prepareStatement(String sql) throws SQLException;
114 * This method creates a new <code>CallableStatement</code> for the
115 * specified SQL string. Thie method is designed to be used with
116 * stored procedures. The default result set type and concurrency
117 * will be used.
119 * @param sql The SQL statement to use in creating this
120 * <code>CallableStatement</code>.
121 * @return A new <code>CallableStatement</code>.
122 * @exception SQLException If an error occurs.
123 * @see CallableStatement
125 CallableStatement prepareCall(String sql) throws SQLException;
128 * This method converts the specified generic SQL statement into the
129 * native grammer of the database this object is connected to.
131 * @param sql The JDBC generic SQL statement.
132 * @return The native SQL statement.
133 * @exception SQLException If an error occurs.
135 String nativeSQL(String sql) throws SQLException;
138 * This method turns auto commit mode on or off. In auto commit mode,
139 * every SQL statement is committed its own transaction. Otherwise a
140 * transaction must be explicitly committed or rolled back.
142 * @param autoCommit <code>true</code> to enable auto commit mode,
143 * <code>false</code> to disable it.
144 * @exception SQLException If an error occurs.
145 * @see #commit()
146 * @see #rollback()
148 void setAutoCommit(boolean autoCommit) throws SQLException;
151 * This method tests whether or not auto commit mode is currently enabled.
152 * In auto commit mode, every SQL statement is committed its own transaction.
153 * Otherwise a transaction must be explicitly committed or rolled back.
155 * @return <code>true</code> if auto commit mode is enabled,
156 * <code>false</code> otherwise.
157 * @exception SQLException If an error occurs.
158 * @see #commit()
159 * @see #rollback()
161 boolean getAutoCommit() throws SQLException;
164 * This method commits any SQL statements executed on this connection since
165 * the last commit or rollback.
167 * @exception SQLException If an error occurs.
169 void commit() throws SQLException;
172 * This method rolls back any SQL statements executed on this connection
173 * since the last commit or rollback.
175 * @exception SQLException If an error occurs.
177 void rollback() throws SQLException;
180 * This method immediately closes this database connection.
182 * @exception SQLException If an error occurs.
184 void close() throws SQLException;
187 * This method tests whether or not this connection has been closed.
189 * @return <code>true</code> if the connection is closed, <code>false</code>
190 * otherwise.
191 * @exception SQLException If an error occurs.
193 boolean isClosed() throws SQLException;
196 * This method returns the meta data for this database connection.
198 * @return The meta data for this database.
199 * @exception SQLException If an error occurs.
200 * @see DatabaseMetaData
202 DatabaseMetaData getMetaData() throws SQLException;
205 * This method turns read only mode on or off. It may not be called while
206 * a transaction is in progress.
208 * @param readOnly <code>true</code> if this connection is read only,
209 * <code>false</code> otherwise.
210 * @exception SQLException If an error occurs.
212 void setReadOnly(boolean readOnly) throws SQLException;
215 * This method tests whether or not this connection is in read only mode.
217 * @return <code>true</code> if the connection is read only <code>false</code>
218 * otherwise.
219 * @exception SQLException If an error occurs.
221 boolean isReadOnly() throws SQLException;
224 * This method sets the name of the catalog in use by this connection.
225 * Note that this method does nothing if catalogs are not supported by
226 * this database.
228 * @param catalog The name of the catalog to use for this connection.
229 * @exception SQLException If an error occurs.
231 void setCatalog(String catalog) throws SQLException;
234 * This method returns the name of the catalog in use by this connection,
235 * if any.
237 * @return The name of the catalog, or <code>null</code> if none
238 * exists or catalogs are not supported by this database.
239 * @exception SQLException If an error occurs.
241 String getCatalog() throws SQLException;
244 * This method sets the current transaction isolation mode. This must
245 * be one of the constants defined in this interface.
247 * @param level The transaction isolation level.
248 * @exception SQLException If an error occurs.
250 void setTransactionIsolation(int level) throws SQLException;
253 * This method returns the current transaction isolation mode. This will
254 * be one of the constants defined in this interface.
256 * @return The transaction isolation level.
257 * @exception SQLException If an error occurs.
259 int getTransactionIsolation() throws SQLException;
262 * This method returns the first warning that occurred on this connection,
263 * if any. If there were any subsequence warnings, they will be chained
264 * to the first one.
266 * @return The first <code>SQLWarning</code> that occurred, or
267 * <code>null</code> if there have been no warnings.
268 * @exception SQLException If an error occurs.
270 SQLWarning getWarnings() throws SQLException;
273 * This method clears all warnings that have occurred on this connection.
275 * @exception SQLException If an error occurs.
277 void clearWarnings() throws SQLException;
280 * This method creates a new SQL statement with the specified type and
281 * concurrency. Valid values for these parameters are specified in the
282 * <code>ResultSet</code> class.
284 * @param resultSetType The type of result set to use for this statement.
285 * @param resultSetConcurrency The type of concurrency to be used in
286 * the result set for this statement.
287 * @return A new <code>Statement</code> object.
288 * @exception SQLException If an error occurs.
289 * @see Statement
290 * @see ResultSet
292 Statement createStatement(int resultSetType, int resultSetConcurrency)
293 throws SQLException;
296 * This method creates a new <code>PreparedStatement</code> for the specified
297 * SQL string. This method is designed for use with parameterized
298 * statements. The specified result set type and concurrency will be used.
299 * Valid values for these parameters are specified in the
300 * <code>ResultSet</code> class.
302 * @param sql The SQL statement to use in creating this
303 * <code>PreparedStatement</code>.
304 * @param resultSetType The type of result set to use for this statement.
305 * @param resultSetConcurrency The type of concurrency to be used in
306 * the result set for this statement.
307 * @return A new <code>PreparedStatement</code>.
308 * @exception SQLException If an error occurs.
309 * @see PreparedStatement
310 * @see ResultSet
312 PreparedStatement prepareStatement(String sql, int resultSetType,
313 int resultSetConcurrency) throws SQLException;
316 * This method creates a new <code>CallableStatement</code> for the
317 * specified SQL string. Thie method is designed to be used with
318 * stored procedures. The specified result set type and concurrency
319 * will be used. Valid values for these parameters are specified in the
320 * <code>ResultSet</code> class.
322 * @param sql The SQL statement to use in creating this
323 * <code>PreparedStatement</code>.
324 * @param resultSetType The type of result set to use for this statement.
325 * @param resultSetConcurrency The type of concurrency to be used in
326 * the result set for this statement.
327 * @return A new <code>CallableStatement</code>.
328 * @exception SQLException If an error occurs.
329 * @see CallableStatement
330 * @see ResultSet
332 CallableStatement prepareCall(String sql, int resultSetType, int
333 resultSetConcurrency) throws SQLException;
336 * This method returns the mapping of SQL types to Java classes
337 * currently in use by this connection. This mapping will have no
338 * entries unless they have been manually added.
340 * @return The SQL type to Java class mapping.
341 * @exception SQLException If an error occurs.
343 Map<String, Class<?>> getTypeMap() throws SQLException;
346 * This method sets the mapping table for SQL types to Java classes.
347 * Any entries in this map override the defaults.
349 * @param map The new SQL mapping table.
350 * @exception SQLException If an error occurs.
352 void setTypeMap(Map<String, Class<?>> map) throws SQLException;
355 * Sets the default holdability of <code>ResultSet</code>S that are created
356 * from <code>Statement</code>S using this <code>Connection</code>.
358 * @param holdability The default holdability value to set, this must be one
359 * of <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
360 * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>.
361 * @exception SQLException If an error occurs.
362 * @see ResultSet
363 * @since 1.4
365 void setHoldability(int holdability) throws SQLException;
368 * Gets the default holdability of <code>ResultSet</code>S that are created
369 * from <code>Statement</code>S using this <code>Connection</code>.
371 * @return The current default holdability value, this must be one of
372 * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
373 * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>.
374 * @exception SQLException If an error occurs.
375 * @see ResultSet
376 * @since 1.4
378 int getHoldability() throws SQLException;
381 * Creates a new unnamed savepoint for this <code>Connection</code>
383 * @return The <code>Savepoint</code> object representing the savepoint.
384 * @exception SQLException If an error occurs.
385 * @since 1.4
387 Savepoint setSavepoint() throws SQLException;
390 * Creates a new savepoint with the specifiend name for this
391 * <code>Connection</code>.
393 * @param name The name of the savepoint.
394 * @return The <code>Savepoint</code> object representing the savepoint.
395 * @exception SQLException If an error occurs.
396 * @since 1.4
398 Savepoint setSavepoint(String name) throws SQLException;
401 * Undoes all changes made after the specified savepoint was set.
403 * @param savepoint The safepoint to roll back to.
404 * @exception SQLException If an error occurs.
405 * @since 1.4
407 void rollback(Savepoint savepoint) throws SQLException;
410 * Removes the specified savepoint from this <code>Connection</code>.
411 * Refering to a savepoint after it was removed is an error and will throw an
412 * SQLException.
414 * @param savepoint The savepoint to release.
415 * @exception SQLException If an error occurs.
416 * @since 1.4
418 void releaseSavepoint(Savepoint savepoint) throws SQLException;
421 * This method creates a new SQL statement with the specified type,
422 * concurrency and holdability, instead of using the defaults. Valid values
423 * for these parameters are specified in the <code>ResultSet</code> class.
425 * @param resultSetType The type of result set to use for this statement.
426 * @param resultSetConcurrency The type of concurrency to be used in
427 * the result set for this statement.
428 * @param resultSetHoldability The type of holdability to be usd in the
429 * result set for this statement.
430 * @return A new <code>Statement</code>
431 * @exception SQLException If an error occurs.
432 * @see ResultSet
433 * @since 1.4
435 Statement createStatement(int resultSetType, int
436 resultSetConcurrency, int resultSetHoldability) throws SQLException;
439 * This method creates a new <code>PreparedStatement</code> for the specified
440 * SQL string. This method is designed for use with parameterized
441 * statements. The specified result set type, concurrency and holdability
442 * will be used. Valid values for these parameters are specified in the
443 * <code>ResultSet</code> class.
445 * @param sql The SQL statement to use in creating this
446 * <code>PreparedStatement</code>.
447 * @param resultSetType The type of result set to use for this statement.
448 * @param resultSetConcurrency The type of concurrency to be used in
449 * the result set for this statement.
450 * @param resultSetHoldability The type of holdability to be usd in the
451 * result set for this statement.
452 * @return A new <code>PreparedStatement</code>.
453 * @exception SQLException If an error occurs.
454 * @see PreparedStatement
455 * @see ResultSet
456 * @since 1.4
458 PreparedStatement prepareStatement(String sql, int resultSetType, int
459 resultSetConcurrency, int resultSetHoldability) throws SQLException;
462 * This method creates a new <code>CallableStatement</code> for the
463 * specified SQL string. Thie method is designed to be used with
464 * stored procedures. The specified result set type, concurrency and
465 * holdability will be used. Valid values for these parameters are specified
466 * in the <code>ResultSet</code> class.
468 * @param sql The SQL statement to use in creating this
469 * <code>PreparedStatement</code>.
470 * @param resultSetType The type of result set to use for this statement.
471 * @param resultSetConcurrency The type of concurrency to be used in
472 * the result set for this statement.
473 * @param resultSetHoldability The type of holdability to be used in the
474 * result set for this statement.
475 * @return A new <code>CallableStatement</code>.
476 * @exception SQLException If an error occurs.
477 * @see CallableStatement
478 * @see ResultSet
479 * @since 1.4
481 CallableStatement prepareCall(String sql, int resultSetType, int
482 resultSetConcurrency, int resultSetHoldability) throws SQLException;
485 * @since 1.4
487 PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
488 throws SQLException;
491 * @since 1.4
493 PreparedStatement prepareStatement(String sql, int[] columnIndexes)
494 throws SQLException;
497 * @since 1.4
499 PreparedStatement prepareStatement(String sql, String[] columnNames)
500 throws SQLException;