public class JDBCConnection extends Object implements Connection, BusyHandler
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
autocommit
Autocommit flag, true means autocommit.
|
protected SQLite.JDBC2z.DatabaseX |
db
Open database.
|
protected String |
enc
Character encoding.
|
protected boolean |
intrans
In-transaction flag.
|
protected int |
timeout
Timeout for Database.exec()
|
protected String |
url
Database URL.
|
protected boolean |
useJulian
Use double/julian date representation.
|
protected String |
vfs
SQLite 3 VFS to use.
|
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE| Constructor and Description |
|---|
JDBCConnection(String url,
String enc,
String pwd,
String drep,
String vfs) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
busy(String table,
int count)
Invoked when a table is locked by another process
or thread.
|
protected boolean |
busy3(SQLite.JDBC2z.DatabaseX db,
int count) |
void |
clearWarnings()
Discards all warnings that may have arisen for this connection.
|
void |
close()
Causes the instant release of all database and driver connection
resources associated with this object.
|
void |
commit()
Commits all of the changes made since the last
commit or
rollback of the associated transaction. |
Array |
createArrayOf(String type,
Object[] elems)
Returns a new
Array containing the given elements. |
Blob |
createBlob()
Returns a new empty Blob.
|
Clob |
createClob()
Returns a new empty Clob.
|
NClob |
createNClob()
Returns a new empty NClob.
|
SQLXML |
createSQLXML()
Returns a new empty SQLXML.
|
Statement |
createStatement()
Returns a new instance of
Statement for issuing SQL commands to
the remote database. |
Statement |
createStatement(int resultSetType,
int resultSetConcurrency)
Returns a new instance of
Statement whose associated ResultSets have the characteristics specified in the type and
concurrency arguments. |
Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Returns a new instance of
Statement whose associated
ResultSets will have the characteristics specified in the
type, concurrency and holdability arguments. |
Struct |
createStruct(String type,
Object[] attrs)
Returns a new
Struct containing the given attributes. |
boolean |
getAutoCommit()
Returns a
boolean indicating whether or not this connection is in
the auto-commit operating mode. |
String |
getCatalog()
Gets this
Connection object's current catalog name. |
Properties |
getClientInfo()
Returns a
Properties object containing all client info properties. |
String |
getClientInfo(String name)
Returns the value corresponding to the given client info property, or null if unset.
|
int |
getHoldability()
Returns the holdability property that any
ResultSet produced by
this instance will have. |
DatabaseMetaData |
getMetaData()
Gets the metadata about the database referenced by this connection.
|
Database |
getSQLiteDatabase() |
int |
getTransactionIsolation()
Returns the transaction isolation level for this connection.
|
Map<String,Class<?>> |
getTypeMap()
Returns the type mapping associated with this
Connection object. |
SQLWarning |
getWarnings()
Gets the first instance of any
SQLWarning objects that may have
been created in the use of this connection. |
boolean |
isClosed()
Returns a
boolean indicating whether or not this connection is in
the closed state. |
boolean |
isReadOnly()
Returns a
boolean indicating whether or not this connection is
currently in the read-only state. |
boolean |
isValid(int timeout)
Returns true if this connection is still open and valid, false otherwise.
|
boolean |
isWrapperFor(Class iface)
If the caller is a wrapper of the class or implements the given
interface, the methods return false and vice versa.
|
String |
nativeSQL(String sql)
Returns a string representation of the input SQL statement
sql expressed in the underlying system's native SQL
syntax. |
CallableStatement |
prepareCall(String sql)
Returns a new instance of
CallableStatement that may be used for
making stored procedure calls to the database. |
CallableStatement |
prepareCall(String sql,
int x,
int y)
Returns a new instance of
CallableStatement that may be used for
making stored procedure calls to the database. |
CallableStatement |
prepareCall(String sql,
int x,
int y,
int z)
Returns a new instance of
CallableStatement that may be used for
making stored procedure calls to the database. |
PreparedStatement |
prepareStatement(String sql)
Returns a new instance of
PreparedStatement that may be used any
number of times to execute parameterized requests on the database server. |
PreparedStatement |
prepareStatement(String sql,
int autokeys)
Creates a default
PreparedStatement that can retrieve
automatically generated keys. |
PreparedStatement |
prepareStatement(String sql,
int[] colIndexes)
Creates a default
PreparedStatement that can retrieve the
auto-generated keys designated by a supplied array. |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency)
Creates a
PreparedStatement that generates ResultSets
with the specified values of resultSetType and resultSetConcurrency. |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Creates a
PreparedStatement that generates ResultSets
with the specified type, concurrency and holdability |
PreparedStatement |
prepareStatement(String sql,
String[] columns)
Creates a default
PreparedStatement that can retrieve the
auto-generated keys designated by a supplied array. |
void |
releaseSavepoint(Savepoint x)
Releases the specified
savepoint from the present transaction. |
void |
rollback()
Rolls back all updates made so far in this transaction and
relinquishes all acquired database locks.
|
void |
rollback(Savepoint x)
Undoes all changes made after the supplied
Savepoint object was
set. |
void |
setAutoCommit(boolean ac)
Sets this connection's auto-commit mode
on or off. |
void |
setCatalog(String catalog)
Sets the catalog name for this connection.
|
void |
setClientInfo(Properties prop)
Replaces all client info properties with the name/value pairs from
properties. |
void |
setClientInfo(String name,
String value)
Sets the client info property
name to value. |
void |
setHoldability(int holdability)
Sets the holdability of the
ResultSets created by this Connection. |
void |
setReadOnly(boolean ro)
Sets this connection to read-only mode.
|
Savepoint |
setSavepoint()
Creates an unnamed
Savepoint in the current transaction. |
Savepoint |
setSavepoint(String name)
Creates a named
Savepoint in the current transaction. |
void |
setTransactionIsolation(int level)
Sets the transaction isolation level for this Connection.
|
void |
setTypeMap(Map map)
Sets the
TypeMap for this connection. |
<T> T |
unwrap(Class<T> iface)
Returns an object that implements the given interface.
|
protected SQLite.JDBC2z.DatabaseX db
protected String url
protected String enc
protected String vfs
protected boolean autocommit
protected boolean intrans
protected int timeout
protected boolean useJulian
public JDBCConnection(String url, String enc, String pwd, String drep, String vfs) throws SQLException
SQLExceptionpublic boolean busy(String table, int count)
BusyHandlerbusy in interface BusyHandlertable - the name of the locked tablecount - number of times the table was lockedprotected boolean busy3(SQLite.JDBC2z.DatabaseX db,
int count)
public Database getSQLiteDatabase()
public Statement createStatement()
ConnectionStatement for issuing SQL commands to
the remote database.
ResultSets generated by the returned statement will default to
type ResultSet.TYPE_FORWARD_ONLY and concurrency level ResultSet.CONCUR_READ_ONLY.
createStatement in interface ConnectionStatement object with default settings.ResultSetpublic Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
ConnectionStatement whose associated ResultSets have the characteristics specified in the type and
concurrency arguments.createStatement in interface ConnectionresultSetType - one of the following type specifiers:
resultSetConcurrency - one of the following concurrency mode specifiers:
Statement capable of manufacturing
ResultSets that satisfy the specified resultSetType and resultSetConcurrency values.SQLException - if there is a problem accessing the databasepublic DatabaseMetaData getMetaData() throws SQLException
ConnectionDatabaseMetaData describes the database topography,
available stored procedures, SQL syntax and so on.getMetaData in interface ConnectionDatabaseMetaData object containing the database
description.SQLException - if there is a problem accessing the a database.public void close()
throws SQLException
Connection
It is strongly recommended that all connections are closed before they
are dereferenced by the application ready for garbage collection.
Although the finalize method of the connection closes the
connection before garbage collection takes place, it is not advisable to
leave the close operation to take place in this way. Mainly
because undesired side-effects may appear.
close in interface AutoCloseableclose in interface ConnectionSQLException - if there is a problem accessing the database.public boolean isClosed()
throws SQLException
Connectionboolean indicating whether or not this connection is in
the closed state. The closed state may be entered into as
a consequence of a successful invocation of the Connection.close() method
or else if an error has occurred that prevents the connection from
functioning normally.isClosed in interface Connectiontrue if closed, otherwise false.SQLException - if there is a problem accessing the database.public boolean isReadOnly()
throws SQLException
Connectionboolean indicating whether or not this connection is
currently in the read-only state.isReadOnly in interface Connectiontrue if in read-only state, otherwise false.SQLException - if there is a problem accessing the database.public void clearWarnings()
throws SQLException
ConnectionConnection.getWarnings() will return null
up until a new warning condition occurs.clearWarnings in interface ConnectionSQLException - if there is a problem accessing the database.public void commit()
throws SQLException
Connectioncommit or
rollback of the associated transaction. All locks in the database
held by this connection are also relinquished. Calling this operation on
connection objects in auto-commit mode leads to an error.commit in interface ConnectionSQLException - if there is a problem accessing the database or if the target
connection instance is in auto-commit mode.public boolean getAutoCommit()
throws SQLException
Connectionboolean indicating whether or not this connection is in
the auto-commit operating mode.getAutoCommit in interface Connectiontrue if auto-commit is on, otherwise false.SQLException - if there is a problem accessing the database.public String getCatalog() throws SQLException
ConnectionConnection object's current catalog name.getCatalog in interface Connectionnull if there is no catalog
name.SQLException - if there is a problem accessing the database.public int getTransactionIsolation()
throws SQLException
ConnectiongetTransactionIsolation in interface ConnectionSQLException - if there is a problem accessing the database.Connection.TRANSACTION_NONE,
Connection.TRANSACTION_READ_COMMITTED,
Connection.TRANSACTION_READ_UNCOMMITTED,
Connection.TRANSACTION_REPEATABLE_READ,
Connection.TRANSACTION_SERIALIZABLEpublic SQLWarning getWarnings() throws SQLException
ConnectionSQLWarning objects that may have
been created in the use of this connection. If at least one warning has
occurred then this operation returns the first one reported. A null indicates that no warnings have occurred.
By invoking the SQLWarning.getNextWarning() method of the
returned SQLWarning object it is possible to obtain all of
this connection's warning objects.
getWarnings in interface Connectionnull).SQLException - if there is a problem accessing the database or if the call
has been made on a connection which has been previously
closed.public String nativeSQL(String sql) throws SQLException
Connectionsql expressed in the underlying system's native SQL
syntax.nativeSQL in interface Connectionsql - the JDBC form of an SQL statement.SQLException - if there is a problem accessing the databasepublic CallableStatement prepareCall(String sql) throws SQLException
ConnectionCallableStatement that may be used for
making stored procedure calls to the database.prepareCall in interface Connectionsql - the SQL statement that calls the stored functionCallableStatement representing the SQL
statement. ResultSets emitted from this CallableStatement will default to type
ResultSet.TYPE_FORWARD_ONLY and concurrency
ResultSet.CONCUR_READ_ONLY.SQLException - if a problem occurs accessing the database.public CallableStatement prepareCall(String sql, int x, int y) throws SQLException
ConnectionCallableStatement that may be used for
making stored procedure calls to the database. ResultSets emitted
from this CallableStatement will satisfy the specified resultSetType and resultSetConcurrency values.prepareCall in interface Connectionsql - the SQL statementx - one of the following type specifiers:
y - one of the following concurrency mode specifiers:
CallableStatement representing the
precompiled SQL statement. ResultSets emitted from this
CallableStatement will satisfy the specified resultSetType and resultSetConcurrency values.SQLException - if a problem occurs accessing the databasepublic PreparedStatement prepareStatement(String sql) throws SQLException
ConnectionPreparedStatement that may be used any
number of times to execute parameterized requests on the database server.
Subject to JDBC driver support, this operation will attempt to send the
precompiled version of the statement to the database. If
the driver does not support precompiled statements, the statement will
not reach the database server until it is executed. This distinction
determines the moment when SQLExceptions get raised.
By default, ResultSets from the returned object will be
ResultSet.TYPE_FORWARD_ONLY type with a
ResultSet.CONCUR_READ_ONLY mode of concurrency.
prepareStatement in interface Connectionsql - the SQL statement.PreparedStatement containing the supplied SQL
statement.SQLException - if there is a problem accessing the database.public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
ConnectionPreparedStatement that generates ResultSets
with the specified values of resultSetType and resultSetConcurrency.prepareStatement in interface Connectionsql - the SQL statement. It can contain one or more '?'
IN parameter placeholders.resultSetType - one of the following type specifiers:
resultSetConcurrency - one of the following concurrency mode specifiers:
PreparedStatement containing the SQL
statement sql. ResultSets emitted from this
PreparedStatement will satisfy the specified resultSetType and resultSetConcurrency values.SQLException - if a problem occurs accessing the database.public void rollback()
throws SQLException
Connectionrollback in interface ConnectionSQLException - if there is a problem with the database or if the method is
called while in auto-commit mode of operation.public void setAutoCommit(boolean ac)
throws SQLException
Connectionon or off.
Putting a Connection into auto-commit mode means that all associated SQL
statements are run and committed as separate transactions.
By contrast, setting auto-commit to off means that associated SQL
statements get grouped into transactions that need to be completed by
explicit calls to either the Connection.commit() or Connection.rollback()
methods.
Auto-commit is the default mode for new connection instances.
When in this mode, commits will automatically occur upon successful SQL
statement completion or upon successful completion of an execute.
Statements are not considered successfully completed until all associated
ResultSets and output parameters have been obtained or closed.
Calling this operation during an uncommitted transaction will result in it being committed.
setAutoCommit in interface Connectionac - boolean indication of whether to put the target
connection into auto-commit mode (true) or not (
false).SQLException - if there is a problem accessing the database.public void setCatalog(String catalog) throws SQLException
ConnectionsetCatalog in interface Connectioncatalog - the catalog name to use.SQLException - if there is a problem accessing the database.public void setReadOnly(boolean ro)
throws SQLException
ConnectionThis serves as a hint to the driver, which can enable database optimizations.
setReadOnly in interface Connectionro - true to set the Connection to read only mode. false disables read-only mode.SQLException - if there is a problem accessing the database.public void setTransactionIsolation(int level)
throws SQLException
ConnectionIf this method is called during a transaction, the results are implementation defined.
setTransactionIsolation in interface Connectionlevel - the new transaction isolation level to use from the following
list of possible values:
SQLException - if there is a problem with the database or if the value of
level is not one of the expected constant values.public Map<String,Class<?>> getTypeMap() throws SQLException
ConnectionConnection object.
The type mapping must be set on the application level.getTypeMap in interface Connectionjava.util.Map.SQLException - if there is a problem accessing the database.public void setTypeMap(Map map) throws SQLException
ConnectionTypeMap for this connection. The input map
should contain mappings between complex Java and SQL types.setTypeMap in interface Connectionmap - the new type map.SQLException - if there is a problem accessing the database or if map is not an instance of Map.public int getHoldability()
throws SQLException
ConnectionResultSet produced by
this instance will have.getHoldability in interface ConnectionSQLException - if there is a problem accessing the a database.public void setHoldability(int holdability)
throws SQLException
ConnectionResultSets created by this Connection.setHoldability in interface Connectionholdability - one of the following holdability mode specifiers:
SQLException - if there is a problem accessing the databasepublic Savepoint setSavepoint() throws SQLException
ConnectionSavepoint in the current transaction.setSavepoint in interface ConnectionSavepoint object for this savepoint.SQLException - if there is a problem accessing the database.public Savepoint setSavepoint(String name) throws SQLException
ConnectionSavepoint in the current transaction.setSavepoint in interface Connectionname - the name to use for the new Savepoint.Savepoint object for this savepoint.SQLException - if there is a problem accessing the database.public void rollback(Savepoint x) throws SQLException
ConnectionSavepoint object was
set. This method should only be used when auto-commit mode is disabled.rollback in interface Connectionx - the Savepoint to roll back toSQLException - if there is a problem accessing the database.public void releaseSavepoint(Savepoint x) throws SQLException
Connectionsavepoint from the present transaction. Once removed,
the Savepoint is considered invalid and should not be referenced
further.releaseSavepoint in interface Connectionx - the object targeted for removal.SQLException - if there is a problem with accessing the database or if
savepoint is considered not valid in this
transaction.public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
ConnectionStatement whose associated
ResultSets will have the characteristics specified in the
type, concurrency and holdability arguments.createStatement in interface ConnectionresultSetType - one of the following type specifiers:
resultSetConcurrency - one of the following concurrency mode specifiers:
resultSetHoldability - one of the following holdability mode specifiers:
Statement capable of
manufacturing ResultSets that satisfy the
specified resultSetType,
resultSetConcurrency and
resultSetHoldability values.SQLException - if there is a problem accessing the database.public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
ConnectionPreparedStatement that generates ResultSets
with the specified type, concurrency and holdabilityprepareStatement in interface Connectionsql - the SQL statement. It can contain one or more '?' IN
parameter placeholders.resultSetType - one of the following type specifiers:
resultSetConcurrency - one of the following concurrency mode specifiers:
resultSetHoldability - one of the following holdability mode specifiers:
PreparedStatement containing the SQL
statement sql. ResultSets emitted from this
PreparedStatement will satisfy the specified resultSetType, resultSetConcurrency and resultSetHoldability values.SQLException - if a problem occurs accessing the database.public CallableStatement prepareCall(String sql, int x, int y, int z) throws SQLException
ConnectionCallableStatement that may be used for
making stored procedure calls to the database. ResultSets created
from this CallableStatement will have characteristics determined
by the specified type, concurrency and holdability arguments.prepareCall in interface Connectionsql - the SQL statementx - one of the following type specifiers:
y - one of the following concurrency mode specifiers:
z - one of the following holdability mode specifiers:
CallableStatement representing the
precompiled SQL statement. ResultSets emitted from this
CallableStatement will satisfy the specified resultSetType, resultSetConcurrency and resultSetHoldability values.SQLException - if a problem occurs accessing the database.public PreparedStatement prepareStatement(String sql, int autokeys) throws SQLException
ConnectionPreparedStatement that can retrieve
automatically generated keys. Parameter autoGeneratedKeys may be
used to tell the driver whether such keys should be made accessible.
This is only relevant when the sql statement is an insert
statement.
An SQL statement which may have IN parameters can be stored and
precompiled in a PreparedStatement. The PreparedStatement
can then be then be used to execute the statement multiple times in an
efficient way.
Subject to JDBC driver support, this operation will attempt to send the
precompiled version of the statement to the database. If
the driver does not support precompiled statements, the statement will
not reach the database server until it is executed. This distinction
determines the moment when SQLExceptions get raised.
By default, ResultSets from the returned object will be
ResultSet.TYPE_FORWARD_ONLY type with a
ResultSet.CONCUR_READ_ONLY mode of concurrency.
prepareStatement in interface Connectionsql - the SQL statement.autokeys - one of the following generated key options:
PreparedStatement instance representing the input
SQL statement.SQLException - if there is a problem accessing the database.public PreparedStatement prepareStatement(String sql, int[] colIndexes) throws SQLException
ConnectionPreparedStatement that can retrieve the
auto-generated keys designated by a supplied array. If sql is an
SQL INSERT statement, the parameter columnIndexes is expected
to hold the index values for each column in the statement's intended
database table containing the autogenerated-keys of interest. Otherwise
columnIndexes is ignored.
Subject to JDBC driver support, this operation will attempt to send the
precompiled version of the statement to the database. If
the driver does not support precompiled statements, the statement will
not reach the database server until it is executed. This distinction
determines the moment when SQLExceptions get raised.
By default, ResultSets from the returned object will be
ResultSet.TYPE_FORWARD_ONLY type with a
ResultSet.CONCUR_READ_ONLY concurrency mode.
prepareStatement in interface Connectionsql - the SQL statement.colIndexes - the indexes of the columns for which auto-generated keys
should be made available.SQLException - if a problem occurs accessing the database.public PreparedStatement prepareStatement(String sql, String[] columns) throws SQLException
ConnectionPreparedStatement that can retrieve the
auto-generated keys designated by a supplied array. If sql is an
SQL INSERT statement, columnNames is expected to hold the
names of each column in the statement's associated database table
containing the autogenerated-keys of interest. Otherwise columnNames is ignored.
Subject to JDBC driver support, this operation will attempt to send the
precompiled version of the statement to the database. Alternatively, if
the driver is not capable of handling precompiled statements, the
statement will not reach the database server until it is executed. This
will have a bearing on precisely when SQLException
instances get raised.
By default, ResultSets from the returned object will be
ResultSet.TYPE_FORWARD_ONLY type with a
ResultSet.CONCUR_READ_ONLY concurrency mode.
prepareStatement in interface Connectionsql - the SQL statement.columns - the names of the columns for which auto-generated keys should
be made available.SQLException - if a problem occurs accessing the database.public Clob createClob() throws SQLException
ConnectioncreateClob in interface ConnectionSQLException - if this connection is closed, or there's a problem creating a new clob.public Blob createBlob() throws SQLException
ConnectioncreateBlob in interface ConnectionSQLException - if this connection is closed, or there's a problem creating a new blob.public NClob createNClob() throws SQLException
ConnectioncreateNClob in interface ConnectionSQLException - if this connection is closed, or there's a problem creating a new nclob.public SQLXML createSQLXML() throws SQLException
ConnectioncreateSQLXML in interface ConnectionSQLException - if this connection is closed, or there's a problem creating a new XML.public boolean isValid(int timeout)
throws SQLException
ConnectionisValid in interface Connectiontimeout - number of seconds to wait for a response before giving up and returning false,
0 to wait foreverSQLException - if timeout < 0public void setClientInfo(String name, String value) throws SQLClientInfoException
Connectionname to value. A value of null clears the
client info property.setClientInfo in interface ConnectionSQLClientInfoException - if this connection is closed, or there's a problem setting
the property.public void setClientInfo(Properties prop) throws SQLClientInfoException
Connectionproperties.
All existing properties are removed. If an exception is thrown, the resulting state of
this connection's client info properties is undefined.setClientInfo in interface ConnectionSQLClientInfoException - if this connection is closed, or there's a problem setting
a property.public String getClientInfo(String name) throws SQLException
ConnectiongetClientInfo in interface ConnectionSQLClientInfoException - if this connection is closed, or there's a problem getting
the property.SQLExceptionpublic Properties getClientInfo() throws SQLException
ConnectionProperties object containing all client info properties.getClientInfo in interface ConnectionSQLClientInfoException - if this connection is closed, or there's a problem getting
a property.SQLExceptionpublic Array createArrayOf(String type, Object[] elems) throws SQLException
ConnectionArray containing the given elements.createArrayOf in interface Connectiontype - the SQL name of the type of the array elementsSQLClientInfoException - if this connection is closed, or there's a problem creating
the array.SQLExceptionpublic Struct createStruct(String type, Object[] attrs) throws SQLException
ConnectionStruct containing the given attributes.createStruct in interface Connectiontype - the SQL name of the type of the struct attributesSQLClientInfoException - if this connection is closed, or there's a problem creating
the array.SQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
Wrapperunwrap in interface Wrapperiface - -
the class that defines the interfaceSQLException - -
if there is no object implementing the specific interfacepublic boolean isWrapperFor(Class iface) throws SQLException
WrapperisWrapperFor in interface Wrapperiface - -
the class that defines the interfaceSQLException - -
when an error occurs when judges the object