1 /* Connection.java -- Manage a database connection.
2 Copyright (C) 1999, 2000, 2002 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)
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., 59 Temple Place, Suite 330, Boston, MA
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
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. */
44 * This interface provides methods for managing a connection to a database.
46 * @author Aaron M. Renn (arenn@urbanophile.com)
48 public interface Connection
51 * This transaction isolation level indicates that transactions are not
54 int TRANSACTION_NONE = 0;
57 * This transaction isolation level indicates that one transaction can
58 * read modifications by other transactions before the other transactions
59 * have committed their changes. This could result in invalid reads.
61 int TRANSACTION_READ_UNCOMMITTED = 1;
64 * This transaction isolation leve indicates that only committed data from
65 * other transactions will be read. If a transaction reads a row, then
66 * another transaction commits a change to that row, the first transaction
67 * would retrieve the changed row on subsequent reads of the same row.
69 int TRANSACTION_READ_COMMITTED = 2;
72 * This transaction isolation level indicates that only committed data from
73 * other transactions will be read. It also ensures that data read from
74 * a row will not be different on a subsequent read even if another
75 * transaction commits a change.
77 int TRANSACTION_REPEATABLE_READ = 4;
80 * This transaction isolation level indicates that only committed data from
81 * other transactions will be read. It also ensures that data read from
82 * a row will not be different on a subsequent read even if another
83 * transaction commits a change. Additionally, rows modified by other
84 * transactions will not affect the result set returned during subsequent
85 * executions of the same WHERE clause in this transaction.
87 int TRANSACTION_SERIALIZABLE = 8;
90 * This method creates a new SQL statement. The default result set type
91 * and concurrency will be used.
93 * @return A new <code>Statement</code> object.
94 * @exception SQLException If an error occurs.
97 Statement createStatement() throws SQLException;
100 * This method creates a new <code>PreparedStatement</code> for the specified
101 * SQL string. This method is designed for use with parameterized
102 * statements. The default result set type and concurrency will be used.
104 * @param The SQL statement to use in creating this
105 * <code>PreparedStatement</code>.
106 * @return A new <code>PreparedStatement</code>.
107 * @exception SQLException If an error occurs.
108 * @see PreparedStatement
110 PreparedStatement prepareStatement(String sql) throws SQLException;
113 * This method creates a new <code>CallableStatement</code> for the
114 * specified SQL string. Thie method is designed to be used with
115 * stored procedures. The default result set type and concurrency
118 * @param The SQL statement to use in creating this
119 * <code>CallableStatement</code>.
120 * @return A new <code>CallableStatement</code>.
121 * @exception SQLException If an error occurs.
122 * @see CallableStatement
124 CallableStatement prepareCall(String sql) throws SQLException;
127 * This method converts the specified generic SQL statement into the
128 * native grammer of the database this object is connected to.
130 * @param The JDBC generic SQL statement.
131 * @return The native SQL statement.
132 * @exception SQLException If an error occurs.
134 String nativeSQL(String sql) throws SQLException;
137 * This method turns auto commit mode on or off. In auto commit mode,
138 * every SQL statement is committed its own transaction. Otherwise a
139 * transaction must be explicitly committed or rolled back.
141 * @param autoCommit <code>true</code> to enable auto commit mode,
142 * <code>false</code> to disable it.
143 * @exception SQLException If an error occurs.
147 void setAutoCommit(boolean autoCommit) throws SQLException;
150 * This method tests whether or not auto commit mode is currently enabled.
151 * In auto commit mode, every SQL statement is committed its own transaction.
152 * Otherwise a transaction must be explicitly committed or rolled back.
154 * @return <code>true</code> if auto commit mode is enabled,
155 * <code>false</code> otherwise.
157 * @exception SQLException If an error occurs.
162 boolean getAutoCommit() throws SQLException;
165 * This method commits any SQL statements executed on this connection since
166 * the last commit or rollback.
168 * @exception SQLException If an error occurs.
170 void commit() throws SQLException;
173 * This method rolls back any SQL statements executed on this connection
174 * since the last commit or rollback.
176 * @exception SQLException If an error occurs.
178 void rollback() throws SQLException;
181 * This method immediately closes this database connection.
183 * @exception SQLException If an error occurs.
185 void close() throws SQLException;
188 * This method tests whether or not this connection has been closed.
190 * @return <code>true</code> if the connection is closed, <code>false</code>
192 * @exception SQLException If an error occurs.
194 boolean isClosed() throws SQLException;
197 * This method returns the meta data for this database connection.
199 * @return The meta data for this database.
200 * @exception SQLException If an error occurs.
201 * @see DatabaseMetaData
203 DatabaseMetaData getMetaData() throws SQLException;
206 * This method turns read only mode on or off. It may not be called while
207 * a transaction is in progress.
209 * @param readOnly <code>true</code> if this connection is read only,
210 * <code>false</code> otherwise.
211 * @exception SQLException If an error occurs.
213 void setReadOnly(boolean readOnly) throws SQLException;
216 * This method tests whether or not this connection is in read only mode.
218 * @return <code>true</code> if the connection is read only <code>false</code>
220 * @exception SQLException If an error occurs.
222 boolean isReadOnly() throws SQLException;
225 * This method sets the name of the catalog in use by this connection.
226 * Note that this method does nothing if catalogs are not supported by
229 * @param catalog The name of the catalog to use for this connection.
230 * @exception SQLException If an error occurs.
232 void setCatalog(String catalog) throws SQLException;
235 * This method returns the name of the catalog in use by this connection,
238 * @return The name of the catalog, or <code>null</code> if one does not
239 * exist or catalogs are not supported by this database.
240 * @exception SQLException If an error occurs.
242 String getCatalog() throws SQLException;
245 * This method sets the current transaction isolation mode. This must
246 * be one of the constants defined in this interface.
248 * @param level The transaction isolation level.
249 * @exception SQLException If an error occurs.
251 void setTransactionIsolation(int level) throws SQLException;
254 * This method returns the current transaction isolation mode. This will
255 * be one of the constants defined in this interface.
257 * @return The transaction isolation level.
258 * @exception SQLException If an error occurs.
260 int getTransactionIsolation() throws SQLException;
263 * This method returns the first warning that occurred on this connection,
264 * if any. If there were any subsequence warnings, they will be chained
267 * @return The first <code>SQLWarning</code> that occurred, or
268 * <code>null</code> if there have been no warnings.
269 * @exception SQLException If an error occurs.
271 SQLWarning getWarnings() throws SQLException;
274 * This method clears all warnings that have occurred on this connection.
276 * @exception SQLException If an error occurs.
278 void clearWarnings() throws SQLException;
281 * This method creates a new SQL statement with the specified type and
282 * concurrency. Valid values for these parameters are specified in the
283 * <code>ResultSet</code> class.
285 * @param resultSetType The type of result set to use for this statement.
286 * @param resultSetConcurrency. The type of concurrency to be used in
287 * the result set for this statement.
288 * @return A new <code>Statement</code> object.
289 * @exception SQLException If an error occurs.
293 Statement createStatement(int resultSetType, int resultSetConcurrency)
297 * This method creates a new <code>PreparedStatement</code> for the specified
298 * SQL string. This method is designed for use with parameterized
299 * statements. The specified result set type and concurrency will be used.
300 * Valid values for these parameters are specified in the
301 * <code>ResultSet</code> class.
303 * @param The SQL statement to use in creating this
304 * <code>PreparedStatement</code>.
305 * @param resultSetType The type of result set to use for this statement.
306 * @param resultSetConcurrency. The type of concurrency to be used in
307 * the result set for this statement.
308 * @return A new <code>PreparedStatement</code>.
309 * @exception SQLException If an error occurs.
310 * @see PreparedStatement
313 PreparedStatement prepareStatement(String sql, int resultSetType,
314 int resultSetConcurrency) throws SQLException;
317 * This method creates a new <code>CallableStatement</code> for the
318 * specified SQL string. Thie method is designed to be used with
319 * stored procedures. The specified result set type and concurrency
320 * will be used. Valid values for these parameters are specified in the
321 * <code>ResultSet</code> class.
323 * @param The SQL statement to use in creating this
324 * <code>PreparedStatement</code>.
325 * @param resultSetType The type of result set to use for this statement.
326 * @param resultSetConcurrency. The type of concurrency to be used in
327 * the result set for this statement.
328 * @return A new <code>CallableStatement</code>.
329 * @exception SQLException If an error occurs.
330 * @see CallableStatement
333 CallableStatement prepareCall(String sql, int resultSetType, int
334 resultSetConcurrency) throws SQLException;
337 * This method returns the mapping of SQL types to Java classes
338 * currently in use by this connection. This mapping will have no
339 * entries unless they have been manually added.
341 * @return The SQL type to Java class mapping.
342 * @exception SQLException If an error occurs.
344 Map getTypeMap() throws SQLException;
347 * This method sets the mapping table for SQL types to Java classes.
348 * Any entries in this map override the defaults.
350 * @param map The new SQL mapping table.
351 * @exception SQLException If an error occurs.
353 void setTypeMap(Map map) throws SQLException;
358 void setHoldability(int holdability) throws SQLException;
363 int getHoldability() throws SQLException;
368 Savepoint setSavepoint() throws SQLException;
373 Savepoint setSavepoint(String name) throws SQLException;
378 void rollback(Savepoint savepoint) throws SQLException;
383 void releaseSavepoint(Savepoint savepoint) throws SQLException;
388 Statement createStatement(int resultSetType, int
389 resultSetConcurrency, int resultSetHoldability) throws SQLException;
394 PreparedStatement prepareStatement(String sql, int resultSetType, int
395 resultSetConcurrency, int resultSetHoldability) throws SQLException;
400 CallableStatement prepareCall(String sql, int resultSetType, int
401 resultSetConcurrency, int resultSetHoldability) throws SQLException;
406 PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
412 PreparedStatement prepareStatement(String sql, int[] columnIndexes)
418 PreparedStatement prepareStatement(String sql, String[] columnNames)