1
/* Connection.java -- Manage a database connection.
2
Copyright (C) 1999, 2000 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
52
* This transaction isolation level indicates that transactions are not
55
public static final int TRANSACTION_NONE = 0;
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
public static final int TRANSACTION_READ_UNCOMMITTED = 1;
65
* This transaction isolation leve 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
public static final int TRANSACTION_READ_COMMITTED = 2;
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
public static final int TRANSACTION_REPEATABLE_READ = 4;
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
public static final int TRANSACTION_SERIALIZABLE = 8;
90
/*************************************************************************/
93
* This method creates a new SQL statement. The default result set type
94
* and concurrency will be used.
96
* @return A new <code>Statement</code> object.
98
* @exception SQLException If an error occurs.
102
public abstract Statement
103
createStatement() throws SQLException;
105
/*************************************************************************/
108
* This method creates a new SQL statement with the specified type and
109
* concurrency. Valid values for these parameters are specified in the
110
* <code>ResultSet</code> class.
112
* @param resultSetType The type of result set to use for this statement.
113
* @param resultSetConcurrency. The type of concurrency to be used in
114
* the result set for this statement.
116
* @return A new <code>Statement</code> object.
118
* @exception SQLException If an error occurs.
123
public abstract Statement
124
createStatement(int resultSetType, int resultSetConcurrency)
127
/*************************************************************************/
130
* This method creates a new <code>PreparedStatement</code> for the specified
131
* SQL string. This method is designed for use with parameterized
132
* statements. The default result set type and concurrency will be used.
134
* @param The SQL statement to use in creating this
135
* <code>PreparedStatement</code>.
137
* @return A new <code>PreparedStatement</code>.
139
* @exception SQLException If an error occurs.
141
* @see PreparedStatement
143
public abstract PreparedStatement
144
prepareStatement(String sql) throws SQLException;
146
/*************************************************************************/
149
* This method creates a new <code>PreparedStatement</code> for the specified
150
* SQL string. This method is designed for use with parameterized
151
* statements. The specified result set type and concurrency will be used.
152
* Valid values for these parameters are specified in the
153
* <code>ResultSet</code> class.
155
* @param The SQL statement to use in creating this
156
* <code>PreparedStatement</code>.
157
* @param resultSetType The type of result set to use for this statement.
158
* @param resultSetConcurrency. The type of concurrency to be used in
159
* the result set for this statement.
161
* @return A new <code>PreparedStatement</code>.
163
* @exception SQLException If an error occurs.
165
* @see PreparedStatement
168
public abstract PreparedStatement
169
prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
172
/*************************************************************************/
175
* This method creates a new <code>CallableStatement</code> for the
176
* specified SQL string. Thie method is designed to be used with
177
* stored procedures. The default result set type and concurrency
180
* @param The SQL statement to use in creating this
181
* <code>CallableStatement</code>.
183
* @return A new <code>CallableStatement</code>.
185
* @exception SQLException If an error occurs.
187
* @see CallableStatement
189
public abstract CallableStatement
190
prepareCall(String sql) throws SQLException;
192
/*************************************************************************/
195
* This method creates a new <code>CallableStatement</code> for the
196
* specified SQL string. Thie method is designed to be used with
197
* stored procedures. The specified result set type and concurrency
198
* will be used. Valid values for these parameters are specified in the
199
* <code>ResultSet</code> class.
201
* @param The SQL statement to use in creating this
202
* <code>PreparedStatement</code>.
203
* @param resultSetType The type of result set to use for this statement.
204
* @param resultSetConcurrency. The type of concurrency to be used in
205
* the result set for this statement.
207
* @return A new <code>CallableStatement</code>.
209
* @exception SQLException If an error occurs.
211
* @see CallableStatement
214
public abstract CallableStatement
215
prepareCall(String sql, int resultSetType, int resultSetConcurrency)
218
/*************************************************************************/
221
* This method converts the specified generic SQL statement into the
222
* native grammer of the database this object is connected to.
224
* @param The JDBC generic SQL statement.
226
* @return The native SQL statement.
228
* @exception SQLException If an error occurs.
230
public abstract String
231
nativeSQL(String sql) throws SQLException;
233
/*************************************************************************/
236
* This method tests whether or not auto commit mode is currently enabled.
237
* In auto commit mode, every SQL statement is committed its own transaction.
238
* Otherwise a transaction must be explicitly committed or rolled back.
240
* @return <code>true</code> if auto commit mode is enabled,
241
* <code>false</code> otherwise.
243
* @exception SQLException If an error occurs.
248
public abstract boolean
249
getAutoCommit() throws SQLException;
251
/*************************************************************************/
254
* This method turns auto commit mode on or off. In auto commit mode,
255
* every SQL statement is committed its own transaction. Otherwise a
256
* transaction must be explicitly committed or rolled back.
258
* @param autoCommit <code>true</code> to enable auto commit mode,
259
* <code>false</code> to disable it.
261
* @exception SQLException If an error occurs.
267
setAutoCommit(boolean autoCommit) throws SQLException;
269
/*************************************************************************/
272
* This method commits any SQL statements executed on this connection since
273
* the last commit or rollback.
275
* @exception SQLException If an error occurs.
278
commit() throws SQLException;
280
/*************************************************************************/
283
* This method rolls back any SQL statements executed on this connection
284
* since the last commit or rollback.
286
* @exception SQLException If an error occurs.
289
rollback() throws SQLException;
291
/*************************************************************************/
294
* This method immediately closes this database connection.
296
* @exception SQLException If an error occurs.
299
close() throws SQLException;
301
/*************************************************************************/
304
* This method tests whether or not this connection has been closed.
306
* @return <code>true</code> if the connection is closed, <code>false</code>
309
* @exception SQLException If an error occurs.
311
public abstract boolean
312
isClosed() throws SQLException;
314
/*************************************************************************/
317
* This method returns the meta data for this database connection.
319
* @return The meta data for this database.
321
* @exception SQLException If an error occurs.
323
* @see DatabaseMetaData
325
public abstract DatabaseMetaData
326
getMetaData() throws SQLException;
328
/*************************************************************************/
331
* This method tests whether or not this connection is in read only mode.
333
* @return <code>true</code> if the connection is read only <code>false</code>
336
* @exception SQLException If an error occurs.
338
public abstract boolean
339
isReadOnly() throws SQLException;
341
/*************************************************************************/
344
* This method turns read only mode on or off. It may not be called while
345
* a transaction is in progress.
347
* @param readOnly <code>true</code> if this connection is read only,
348
* <code>false</code> otherwise.
350
* @exception SQLException If an error occurs.
353
setReadOnly(boolean readOnly) throws SQLException;
355
/*************************************************************************/
358
* This method returns the name of the catalog in use by this connection,
361
* @return The name of the catalog, or <code>null</code> if one does not
362
* exist or catalogs are not supported by this database.
364
* @exception SQLException If an error occurs.
366
public abstract String
367
getCatalog() throws SQLException;
369
/*************************************************************************/
372
* This method sets the name of the catalog in use by this connection.
373
* Note that this method does nothing if catalogs are not supported by
376
* @param catalog The name of the catalog to use for this connection.
378
* @exception SQLException If an error occurs.
381
setCatalog(String catalog) throws SQLException;
383
/*************************************************************************/
386
* This method returns the current transaction isolation mode. This will
387
* be one of the constants defined in this interface.
389
* @return The transaction isolation level.
391
* @exception SQLException If an error occurs.
394
getTransactionIsolation() throws SQLException;
396
/*************************************************************************/
399
* This method sets the current transaction isolation mode. This must
400
* be one of the constants defined in this interface.
402
* @param level The transaction isolation level.
404
* @exception SQLException If an error occurs.
407
setTransactionIsolation(int level) throws SQLException;
409
/*************************************************************************/
412
* This method returns the first warning that occurred on this connection,
413
* if any. If there were any subsequence warnings, they will be chained
416
* @return The first <code>SQLWarning</code> that occurred, or
417
* <code>null</code> if there have been no warnings.
419
* @exception SQLException If an error occurs.
421
public abstract SQLWarning
422
getWarnings() throws SQLException;
424
/*************************************************************************/
427
* This method clears all warnings that have occurred on this connection.
429
* @exception SQLException If an error occurs.
432
clearWarnings() throws SQLException;
434
/*************************************************************************/
437
* This method returns the mapping of SQL types to Java classes
438
* currently in use by this connection. This mapping will have no
439
* entries unless they have been manually added.
441
* @return The SQL type to Java class mapping.
443
* @exception SQLException If an error occurs.
446
getTypeMap() throws SQLException;
448
/*************************************************************************/
451
* This method sets the mapping table for SQL types to Java classes.
452
* Any entries in this map override the defaults.
454
* @param map The new SQL mapping table.
456
* @exception SQLException If an error occurs.
459
setTypeMap(Map map) throws SQLException;
461
} // interface Connection