Package org.h2.jdbc
Class JdbcConnection
- java.lang.Object
-
- org.h2.message.TraceObject
-
- org.h2.jdbc.JdbcConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable,java.sql.Connection,java.sql.Wrapper,CastDataProvider,JdbcConnectionBackwardsCompat
- Direct Known Subclasses:
JdbcXAConnection.PooledJdbcConnection
public class JdbcConnection extends TraceObject implements java.sql.Connection, JdbcConnectionBackwardsCompat, CastDataProvider
Represents a connection (session) to a database.Thread safety: the connection is thread-safe, because access is synchronized. Different statements from the same connection may try to execute their commands in parallel, but they will be executed sequentially. If real concurrent execution of these commands is needed, different connections should be used.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringcatalogprivate java.util.Map<java.lang.String,java.lang.String>clientInfoprivate CommandInterfacecommitprivate java.sql.StatementexecutingStatementprivate CommandInterfacegetGeneratedKeysprivate CommandInterfacegetQueryTimeoutprivate CommandInterfacegetReadOnlyprivate intholdabilityprivate static booleankeepOpenStackTraceprivate static java.lang.StringNUM_SERVERSprivate static java.lang.StringPREFIX_SERVERprivate intqueryTimeoutCacheprivate CommandInterfacerollbackprivate intsavepointIdprivate Sessionsessionprivate CommandInterfacesetQueryTimeoutprivate java.lang.Stringurlprivate java.lang.Stringuserprivate CloseWatcherwatcher-
Fields inherited from class org.h2.message.TraceObject
ARRAY, BLOB, CALLABLE_STATEMENT, CLOB, CONNECTION, DATA_SOURCE, DATABASE_META_DATA, PARAMETER_META_DATA, PREPARED_STATEMENT, RESULT_SET, RESULT_SET_META_DATA, SAVEPOINT, SQLXML, STATEMENT, trace, XA_DATA_SOURCE, XID
-
-
Constructor Summary
Constructors Constructor Description JdbcConnection(java.lang.String url, java.util.Properties info, java.lang.String user, java.lang.Object password, boolean forbidCreation)INTERNAL the session closable object does not leak as Eclipse warns - due to the CloseWatcher.JdbcConnection(Session session, java.lang.String user, java.lang.String url)INTERNALJdbcConnection(JdbcConnection clone)INTERNAL
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort(java.util.concurrent.Executor executor)[Not supported]protected voidcheckClosed()INTERNAL.private static voidcheckHoldability(int resultSetHoldability)(package private) static voidcheckMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)Check that the given type map is either null or empty.private static voidcheckRunOver(int i, int len, java.lang.String sql)private static voidcheckTypeConcurrency(int resultSetType, int resultSetConcurrency)voidclearWarnings()Clears all warnings.voidclose()Closes this connection.private static CommandInterfacecloseAndSetNull(CommandInterface command)private voidcloseOld()private voidclosePreparedCommands()voidcommit()Commits the current transaction.private static JdbcSavepointconvertSavepoint(java.sql.Savepoint savepoint)private static java.sql.SQLClientInfoExceptionconvertToClientInfoException(java.sql.SQLException x)java.sql.ArraycreateArrayOf(java.lang.String typeName, java.lang.Object[] elements)Create a new Array object.java.sql.BlobcreateBlob()Create a new empty Blob object.(package private) ValuecreateBlob(java.io.InputStream x, long length)Create a Blob value from this input stream.java.sql.ClobcreateClob()Create a new empty Clob object.(package private) ValuecreateClob(java.io.Reader x, long length)Create a Clob value from this reader.java.sql.NClobcreateNClob()Create a new empty NClob object.java.sql.SQLXMLcreateSQLXML()Create a new SQLXML object with no data.java.sql.StatementcreateStatement()Creates a new statement.java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency)Creates a statement with the specified result set type and concurrency.java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)Creates a statement with the specified result set type, concurrency, and holdability.java.sql.StructcreateStruct(java.lang.String typeName, java.lang.Object[] attributes)[Not supported] Create a new empty Struct object.ValueTimestampTimeZonecurrentTimestamp()Returns the current timestamp with maximum resolution.TimeZoneProvidercurrentTimeZone()Returns the current time zone.private static booleanfound(java.lang.String sql, int start, java.lang.String other)booleangetAutoCommit()Gets the current setting for auto commit.java.lang.StringgetCatalog()Gets the current catalog name.java.util.PropertiesgetClientInfo()Get the client properties.java.lang.StringgetClientInfo(java.lang.String name)Get a client property.(package private) CompareModegetCompareMode()intgetHoldability()Returns the current result set holdability.JavaObjectSerializergetJavaObjectSerializer()Returns the custom Java object serializer, ornull.java.sql.DatabaseMetaDatagetMetaData()Gets the database meta data for this database.ModegetMode()Returns the database mode.intgetNetworkTimeout()[Not supported](package private) intgetQueryTimeout()INTERNALjava.lang.StringgetSchema()Retrieves this current schema name for this connection.SessiongetSession()INTERNALSession.StaticSettingsgetStaticSettings()INTERNALintgetTransactionIsolation()Returns the current transaction isolation level.java.util.Map<java.lang.String,java.lang.Class<?>>getTypeMap()Gets the type map.(package private) java.lang.StringgetURL()(package private) java.lang.StringgetUser()java.sql.SQLWarninggetWarnings()Gets the first warning reported by calls on this object.booleanisClosed()Returns true if this connection has been closed.private static booleanisInternalProperty(java.lang.String name)booleanisReadOnly()Returns true if the database is read-only.booleanisValid(int timeout)Returns true if this connection is still valid.booleanisWrapperFor(java.lang.Class<?> iface)Checks if unwrap can return an object of this class.java.lang.StringnativeSQL(java.lang.String sql)Translates a SQL statement into the database grammar.java.sql.CallableStatementprepareCall(java.lang.String sql)Creates a new callable statement.java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)Creates a callable statement with the specified result set type and concurrency.java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)Creates a callable statement with the specified result set type, concurrency, and holdability.(package private) CommandInterfaceprepareCommand(java.lang.String sql, int fetchSize)Prepare an command.private CommandInterfaceprepareCommand(java.lang.String sql, CommandInterface old)java.sql.PreparedStatementprepareStatement(java.lang.String sql)Creates a new prepared statement.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autoGeneratedKeys)Creates a new prepared statement.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)Creates a new prepared statement.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)Creates a prepared statement with the specified result set type and concurrency.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)Creates a prepared statement with the specified result set type, concurrency, and holdability.java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columnNames)Creates a new prepared statement.voidreleaseSavepoint(java.sql.Savepoint savepoint)Releases a savepoint.voidrollback()Rolls back the current transaction.voidrollback(java.sql.Savepoint savepoint)Rolls back to a savepoint.private voidrollbackInternal()voidsetAutoCommit(boolean autoCommit)Switches auto commit on or off.voidsetCatalog(java.lang.String catalog)Set the default catalog name.voidsetClientInfo(java.lang.String name, java.lang.String value)Set a client property.voidsetClientInfo(java.util.Properties properties)Set the client properties.(package private) voidsetExecutingStatement(java.sql.Statement stat)INTERNALvoidsetHoldability(int holdability)Changes the current result set holdability.voidsetNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds)[Not supported](package private) voidsetQueryTimeout(int seconds)INTERNALvoidsetReadOnly(boolean readOnly)According to the JDBC specs, this setting is only a hint to the database to enable optimizations - it does not cause writes to be prohibited.java.sql.SavepointsetSavepoint()Creates a new unnamed savepoint.java.sql.SavepointsetSavepoint(java.lang.String name)Creates a new named savepoint.voidsetSchema(java.lang.String schema)Sets the given schema name to access.voidsetTransactionIsolation(int level)Changes the current transaction isolation level.voidsetTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)[Partially supported] Sets the type map.java.lang.StringtoString()INTERNALprivate static inttranslateGetEnd(java.lang.String sql, int i, char c)private static java.lang.StringtranslateSQL(java.lang.String sql)Convert JDBC escape sequences in the SQL statement.(package private) static java.lang.StringtranslateSQL(java.lang.String sql, boolean escapeProcessing)Convert JDBC escape sequences in the SQL statement if required.private static java.lang.StringtranslateSQLImpl(java.lang.String sql)<T> Tunwrap(java.lang.Class<T> iface)Return an object of this class if possible.booleanzeroBasedEnums()Returns are ENUM values 0-based.-
Methods inherited from class org.h2.message.TraceObject
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupported
-
-
-
-
Field Detail
-
NUM_SERVERS
private static final java.lang.String NUM_SERVERS
- See Also:
- Constant Field Values
-
PREFIX_SERVER
private static final java.lang.String PREFIX_SERVER
- See Also:
- Constant Field Values
-
keepOpenStackTrace
private static boolean keepOpenStackTrace
-
url
private final java.lang.String url
-
user
private final java.lang.String user
-
holdability
private int holdability
-
session
private Session session
-
commit
private CommandInterface commit
-
rollback
private CommandInterface rollback
-
getReadOnly
private CommandInterface getReadOnly
-
getGeneratedKeys
private CommandInterface getGeneratedKeys
-
setQueryTimeout
private CommandInterface setQueryTimeout
-
getQueryTimeout
private CommandInterface getQueryTimeout
-
savepointId
private int savepointId
-
catalog
private java.lang.String catalog
-
executingStatement
private java.sql.Statement executingStatement
-
watcher
private final CloseWatcher watcher
-
queryTimeoutCache
private int queryTimeoutCache
-
clientInfo
private java.util.Map<java.lang.String,java.lang.String> clientInfo
-
-
Constructor Detail
-
JdbcConnection
public JdbcConnection(java.lang.String url, java.util.Properties info, java.lang.String user, java.lang.Object password, boolean forbidCreation) throws java.sql.SQLExceptionINTERNAL the session closable object does not leak as Eclipse warns - due to the CloseWatcher.- Parameters:
url- of this connectioninfo- of this connectionuser- of this connectionpassword- for the userforbidCreation- whether database creation is forbidden- Throws:
java.sql.SQLException- on failure
-
JdbcConnection
public JdbcConnection(JdbcConnection clone)
INTERNAL- Parameters:
clone- connection to clone
-
JdbcConnection
public JdbcConnection(Session session, java.lang.String user, java.lang.String url)
INTERNAL- Parameters:
session- of this connectionuser- of this connectionurl- of this connection
-
-
Method Detail
-
closeOld
private void closeOld()
-
createStatement
public java.sql.Statement createStatement() throws java.sql.SQLExceptionCreates a new statement.- Specified by:
createStatementin interfacejava.sql.Connection- Returns:
- the new statement
- Throws:
java.sql.SQLException- if the connection is closed
-
createStatement
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws java.sql.SQLExceptionCreates a statement with the specified result set type and concurrency.- Specified by:
createStatementin interfacejava.sql.Connection- Parameters:
resultSetType- the result set type (ResultSet.TYPE_*)resultSetConcurrency- the concurrency (ResultSet.CONCUR_*)- Returns:
- the statement
- Throws:
java.sql.SQLException- if the connection is closed or the result set type or concurrency are not supported
-
createStatement
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLExceptionCreates a statement with the specified result set type, concurrency, and holdability.- Specified by:
createStatementin interfacejava.sql.Connection- Parameters:
resultSetType- the result set type (ResultSet.TYPE_*)resultSetConcurrency- the concurrency (ResultSet.CONCUR_*)resultSetHoldability- the holdability (ResultSet.HOLD* / CLOSE*)- Returns:
- the statement
- Throws:
java.sql.SQLException- if the connection is closed or the result set type, concurrency, or holdability are not supported
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLExceptionCreates a new prepared statement.- Specified by:
prepareStatementin interfacejava.sql.Connection- Parameters:
sql- the SQL statement- Returns:
- the prepared statement
- Throws:
java.sql.SQLException- if the connection is closed
-
getMetaData
public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLExceptionGets the database meta data for this database.- Specified by:
getMetaDatain interfacejava.sql.Connection- Returns:
- the database meta data
- Throws:
java.sql.SQLException- if the connection is closed
-
getSession
public Session getSession()
INTERNAL- Returns:
- session
-
close
public void close() throws java.sql.SQLExceptionCloses this connection. All open statements, prepared statements and result sets that where created by this connection become invalid after calling this method. If there is an uncommitted transaction, it will be rolled back.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
closePreparedCommands
private void closePreparedCommands()
-
closeAndSetNull
private static CommandInterface closeAndSetNull(CommandInterface command)
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLExceptionSwitches auto commit on or off. Enabling it commits an uncommitted transaction, if there is one.- Specified by:
setAutoCommitin interfacejava.sql.Connection- Parameters:
autoCommit- true for auto commit on, false for off- Throws:
java.sql.SQLException- if the connection is closed
-
getAutoCommit
public boolean getAutoCommit() throws java.sql.SQLExceptionGets the current setting for auto commit.- Specified by:
getAutoCommitin interfacejava.sql.Connection- Returns:
- true for on, false for off
- Throws:
java.sql.SQLException- if the connection is closed
-
commit
public void commit() throws java.sql.SQLExceptionCommits the current transaction. This call has only an effect if auto commit is switched off.- Specified by:
commitin interfacejava.sql.Connection- Throws:
java.sql.SQLException- if the connection is closed
-
rollback
public void rollback() throws java.sql.SQLExceptionRolls back the current transaction. This call has only an effect if auto commit is switched off.- Specified by:
rollbackin interfacejava.sql.Connection- Throws:
java.sql.SQLException- if the connection is closed
-
isClosed
public boolean isClosed() throws java.sql.SQLExceptionReturns true if this connection has been closed.- Specified by:
isClosedin interfacejava.sql.Connection- Returns:
- true if close was called
- Throws:
java.sql.SQLException
-
nativeSQL
public java.lang.String nativeSQL(java.lang.String sql) throws java.sql.SQLExceptionTranslates a SQL statement into the database grammar.- Specified by:
nativeSQLin interfacejava.sql.Connection- Parameters:
sql- the SQL statement with or without JDBC escape sequences- Returns:
- the translated statement
- Throws:
java.sql.SQLException- if the connection is closed
-
setReadOnly
public void setReadOnly(boolean readOnly) throws java.sql.SQLExceptionAccording to the JDBC specs, this setting is only a hint to the database to enable optimizations - it does not cause writes to be prohibited.- Specified by:
setReadOnlyin interfacejava.sql.Connection- Parameters:
readOnly- ignored- Throws:
java.sql.SQLException- if the connection is closed
-
isReadOnly
public boolean isReadOnly() throws java.sql.SQLExceptionReturns true if the database is read-only.- Specified by:
isReadOnlyin interfacejava.sql.Connection- Returns:
- if the database is read-only
- Throws:
java.sql.SQLException- if the connection is closed
-
setCatalog
public void setCatalog(java.lang.String catalog) throws java.sql.SQLExceptionSet the default catalog name. This call is ignored.- Specified by:
setCatalogin interfacejava.sql.Connection- Parameters:
catalog- ignored- Throws:
java.sql.SQLException- if the connection is closed
-
getCatalog
public java.lang.String getCatalog() throws java.sql.SQLExceptionGets the current catalog name.- Specified by:
getCatalogin interfacejava.sql.Connection- Returns:
- the catalog name
- Throws:
java.sql.SQLException- if the connection is closed
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLExceptionGets the first warning reported by calls on this object.- Specified by:
getWarningsin interfacejava.sql.Connection- Returns:
- null
- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings() throws java.sql.SQLExceptionClears all warnings.- Specified by:
clearWarningsin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLExceptionCreates a prepared statement with the specified result set type and concurrency.- Specified by:
prepareStatementin interfacejava.sql.Connection- Parameters:
sql- the SQL statementresultSetType- the result set type (ResultSet.TYPE_*)resultSetConcurrency- the concurrency (ResultSet.CONCUR_*)- Returns:
- the prepared statement
- Throws:
java.sql.SQLException- if the connection is closed or the result set type or concurrency are not supported
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws java.sql.SQLExceptionChanges the current transaction isolation level. Calling this method will commit an open transaction, even if the new level is the same as the old one.- Specified by:
setTransactionIsolationin interfacejava.sql.Connection- Parameters:
level- the new transaction isolation level: Connection.TRANSACTION_READ_UNCOMMITTED, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_REPEATABLE_READ, 6 (SNAPSHOT), or Connection.TRANSACTION_SERIALIZABLE- Throws:
java.sql.SQLException- if the connection is closed or the isolation level is not valid
-
setQueryTimeout
void setQueryTimeout(int seconds) throws java.sql.SQLExceptionINTERNAL- Throws:
java.sql.SQLException
-
getQueryTimeout
int getQueryTimeout() throws java.sql.SQLExceptionINTERNAL- Throws:
java.sql.SQLException
-
getTransactionIsolation
public int getTransactionIsolation() throws java.sql.SQLExceptionReturns the current transaction isolation level.- Specified by:
getTransactionIsolationin interfacejava.sql.Connection- Returns:
- the isolation level
- Throws:
java.sql.SQLException- if the connection is closed
-
setHoldability
public void setHoldability(int holdability) throws java.sql.SQLExceptionChanges the current result set holdability.- Specified by:
setHoldabilityin interfacejava.sql.Connection- Parameters:
holdability- ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT;- Throws:
java.sql.SQLException- if the connection is closed or the holdability is not supported
-
getHoldability
public int getHoldability() throws java.sql.SQLExceptionReturns the current result set holdability.- Specified by:
getHoldabilityin interfacejava.sql.Connection- Returns:
- the holdability
- Throws:
java.sql.SQLException- if the connection is closed
-
getTypeMap
public java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap() throws java.sql.SQLExceptionGets the type map.- Specified by:
getTypeMapin interfacejava.sql.Connection- Returns:
- null
- Throws:
java.sql.SQLException- if the connection is closed
-
setTypeMap
public void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map) throws java.sql.SQLException[Partially supported] Sets the type map. This is only supported if the map is empty or null.- Specified by:
setTypeMapin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLExceptionCreates a new callable statement.- Specified by:
prepareCallin interfacejava.sql.Connection- Parameters:
sql- the SQL statement- Returns:
- the callable statement
- Throws:
java.sql.SQLException- if the connection is closed or the statement is not valid
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLExceptionCreates a callable statement with the specified result set type and concurrency.- Specified by:
prepareCallin interfacejava.sql.Connection- Parameters:
sql- the SQL statementresultSetType- the result set type (ResultSet.TYPE_*)resultSetConcurrency- the concurrency (ResultSet.CONCUR_*)- Returns:
- the callable statement
- Throws:
java.sql.SQLException- if the connection is closed or the result set type or concurrency are not supported
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLExceptionCreates a callable statement with the specified result set type, concurrency, and holdability.- Specified by:
prepareCallin interfacejava.sql.Connection- Parameters:
sql- the SQL statementresultSetType- the result set type (ResultSet.TYPE_*)resultSetConcurrency- the concurrency (ResultSet.CONCUR_*)resultSetHoldability- the holdability (ResultSet.HOLD* / CLOSE*)- Returns:
- the callable statement
- Throws:
java.sql.SQLException- if the connection is closed or the result set type, concurrency, or holdability are not supported
-
setSavepoint
public java.sql.Savepoint setSavepoint() throws java.sql.SQLExceptionCreates a new unnamed savepoint.- Specified by:
setSavepointin interfacejava.sql.Connection- Returns:
- the new savepoint
- Throws:
java.sql.SQLException
-
setSavepoint
public java.sql.Savepoint setSavepoint(java.lang.String name) throws java.sql.SQLExceptionCreates a new named savepoint.- Specified by:
setSavepointin interfacejava.sql.Connection- Parameters:
name- the savepoint name- Returns:
- the new savepoint
- Throws:
java.sql.SQLException
-
rollback
public void rollback(java.sql.Savepoint savepoint) throws java.sql.SQLExceptionRolls back to a savepoint.- Specified by:
rollbackin interfacejava.sql.Connection- Parameters:
savepoint- the savepoint- Throws:
java.sql.SQLException
-
releaseSavepoint
public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLExceptionReleases a savepoint.- Specified by:
releaseSavepointin interfacejava.sql.Connection- Parameters:
savepoint- the savepoint to release- Throws:
java.sql.SQLException
-
convertSavepoint
private static JdbcSavepoint convertSavepoint(java.sql.Savepoint savepoint)
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLExceptionCreates a prepared statement with the specified result set type, concurrency, and holdability.- Specified by:
prepareStatementin interfacejava.sql.Connection- Parameters:
sql- the SQL statementresultSetType- the result set type (ResultSet.TYPE_*)resultSetConcurrency- the concurrency (ResultSet.CONCUR_*)resultSetHoldability- the holdability (ResultSet.HOLD* / CLOSE*)- Returns:
- the prepared statement
- Throws:
java.sql.SQLException- if the connection is closed or the result set type, concurrency, or holdability are not supported
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLExceptionCreates a new prepared statement.- Specified by:
prepareStatementin interfacejava.sql.Connection- Parameters:
sql- the SQL statementautoGeneratedKeys-Statement.RETURN_GENERATED_KEYSif generated keys should be available for retrieval,Statement.NO_GENERATED_KEYSif generated keys should not be available- Returns:
- the prepared statement
- Throws:
java.sql.SQLException- if the connection is closed
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLExceptionCreates a new prepared statement.- Specified by:
prepareStatementin interfacejava.sql.Connection- Parameters:
sql- the SQL statementcolumnIndexes- an array of column indexes indicating the columns with generated keys that should be returned from the inserted row- Returns:
- the prepared statement
- Throws:
java.sql.SQLException- if the connection is closed
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLExceptionCreates a new prepared statement.- Specified by:
prepareStatementin interfacejava.sql.Connection- Parameters:
sql- the SQL statementcolumnNames- an array of column names indicating the columns with generated keys that should be returned from the inserted row- Returns:
- the prepared statement
- Throws:
java.sql.SQLException- if the connection is closed
-
prepareCommand
CommandInterface prepareCommand(java.lang.String sql, int fetchSize)
Prepare an command. This will parse the SQL statement.- Parameters:
sql- the SQL statementfetchSize- the fetch size (used in remote connections)- Returns:
- the command
-
prepareCommand
private CommandInterface prepareCommand(java.lang.String sql, CommandInterface old)
-
translateGetEnd
private static int translateGetEnd(java.lang.String sql, int i, char c)
-
translateSQL
private static java.lang.String translateSQL(java.lang.String sql)
Convert JDBC escape sequences in the SQL statement. This method throws an exception if the SQL statement is null.- Parameters:
sql- the SQL statement with or without JDBC escape sequences- Returns:
- the SQL statement without JDBC escape sequences
-
translateSQL
static java.lang.String translateSQL(java.lang.String sql, boolean escapeProcessing)Convert JDBC escape sequences in the SQL statement if required. This method throws an exception if the SQL statement is null.- Parameters:
sql- the SQL statement with or without JDBC escape sequencesescapeProcessing- whether escape sequences should be replaced- Returns:
- the SQL statement without JDBC escape sequences
-
translateSQLImpl
private static java.lang.String translateSQLImpl(java.lang.String sql)
-
checkRunOver
private static void checkRunOver(int i, int len, java.lang.String sql)
-
found
private static boolean found(java.lang.String sql, int start, java.lang.String other)
-
checkTypeConcurrency
private static void checkTypeConcurrency(int resultSetType, int resultSetConcurrency)
-
checkHoldability
private static void checkHoldability(int resultSetHoldability)
-
checkClosed
protected void checkClosed()
INTERNAL. Check if this connection is closed.- Throws:
DbException- if the connection or session is closed
-
getURL
java.lang.String getURL()
-
getUser
java.lang.String getUser()
-
rollbackInternal
private void rollbackInternal()
-
setExecutingStatement
void setExecutingStatement(java.sql.Statement stat)
INTERNAL
-
createClob
public java.sql.Clob createClob() throws java.sql.SQLExceptionCreate a new empty Clob object.- Specified by:
createClobin interfacejava.sql.Connection- Returns:
- the object
- Throws:
java.sql.SQLException
-
createBlob
public java.sql.Blob createBlob() throws java.sql.SQLExceptionCreate a new empty Blob object.- Specified by:
createBlobin interfacejava.sql.Connection- Returns:
- the object
- Throws:
java.sql.SQLException
-
createNClob
public java.sql.NClob createNClob() throws java.sql.SQLExceptionCreate a new empty NClob object.- Specified by:
createNClobin interfacejava.sql.Connection- Returns:
- the object
- Throws:
java.sql.SQLException
-
createSQLXML
public java.sql.SQLXML createSQLXML() throws java.sql.SQLExceptionCreate a new SQLXML object with no data.- Specified by:
createSQLXMLin interfacejava.sql.Connection- Returns:
- the object
- Throws:
java.sql.SQLException
-
createArrayOf
public java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements) throws java.sql.SQLExceptionCreate a new Array object.- Specified by:
createArrayOfin interfacejava.sql.Connection- Parameters:
typeName- the type nameelements- the values- Returns:
- the array
- Throws:
java.sql.SQLException
-
createStruct
public java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes) throws java.sql.SQLException[Not supported] Create a new empty Struct object.- Specified by:
createStructin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
isValid
public boolean isValid(int timeout)
Returns true if this connection is still valid.- Specified by:
isValidin interfacejava.sql.Connection- Parameters:
timeout- the number of seconds to wait for the database to respond (ignored)- Returns:
- true if the connection is valid.
-
setClientInfo
public void setClientInfo(java.lang.String name, java.lang.String value) throws java.sql.SQLClientInfoExceptionSet a client property. This method always throws a SQLClientInfoException in standard mode. In compatibility mode the following properties are supported:- DB2: The properties: ApplicationName, ClientAccountingInformation, ClientUser and ClientCorrelationToken are supported.
- MySQL: All property names are supported.
- Oracle: All properties in the form <namespace>.<key name> are supported.
- PostgreSQL: The ApplicationName property is supported.
- Specified by:
setClientInfoin interfacejava.sql.Connection- Parameters:
name- the name of the propertyvalue- the value- Throws:
java.sql.SQLClientInfoException
-
isInternalProperty
private static boolean isInternalProperty(java.lang.String name)
-
convertToClientInfoException
private static java.sql.SQLClientInfoException convertToClientInfoException(java.sql.SQLException x)
-
setClientInfo
public void setClientInfo(java.util.Properties properties) throws java.sql.SQLClientInfoExceptionSet the client properties. This replaces all existing properties. This method always throws a SQLClientInfoException in standard mode. In compatibility mode some properties may be supported (see setProperty(String, String) for details).- Specified by:
setClientInfoin interfacejava.sql.Connection- Parameters:
properties- the properties (ignored)- Throws:
java.sql.SQLClientInfoException
-
getClientInfo
public java.util.Properties getClientInfo() throws java.sql.SQLExceptionGet the client properties.- Specified by:
getClientInfoin interfacejava.sql.Connection- Returns:
- the property list
- Throws:
java.sql.SQLException
-
getClientInfo
public java.lang.String getClientInfo(java.lang.String name) throws java.sql.SQLExceptionGet a client property.- Specified by:
getClientInfoin interfacejava.sql.Connection- Parameters:
name- the client info name- Returns:
- the property value or null if the property is not found or not supported.
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLExceptionReturn an object of this class if possible.- Specified by:
unwrapin interfacejava.sql.Wrapper- Parameters:
iface- the class- Returns:
- this
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLExceptionChecks if unwrap can return an object of this class.- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Parameters:
iface- the class- Returns:
- whether or not the interface is assignable from this class
- Throws:
java.sql.SQLException
-
createClob
Value createClob(java.io.Reader x, long length)
Create a Clob value from this reader.- Parameters:
x- the readerlength- the length (if smaller or equal than 0, all data until the end of file is read)- Returns:
- the value
-
createBlob
Value createBlob(java.io.InputStream x, long length)
Create a Blob value from this input stream.- Parameters:
x- the input streamlength- the length (if smaller or equal than 0, all data until the end of file is read)- Returns:
- the value
-
setSchema
public void setSchema(java.lang.String schema) throws java.sql.SQLExceptionSets the given schema name to access. Current implementation is case sensitive, i.e. requires schema name to be passed in correct case.- Specified by:
setSchemain interfacejava.sql.Connection- Parameters:
schema- the schema name- Throws:
java.sql.SQLException
-
getSchema
public java.lang.String getSchema() throws java.sql.SQLExceptionRetrieves this current schema name for this connection.- Specified by:
getSchemain interfacejava.sql.Connection- Returns:
- current schema name
- Throws:
java.sql.SQLException
-
abort
public void abort(java.util.concurrent.Executor executor)
[Not supported]- Specified by:
abortin interfacejava.sql.Connection- Parameters:
executor- the executor used by this method
-
setNetworkTimeout
public void setNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds)[Not supported]- Specified by:
setNetworkTimeoutin interfacejava.sql.Connection- Parameters:
executor- the executor used by this methodmilliseconds- the TCP connection timeout
-
getNetworkTimeout
public int getNetworkTimeout()
[Not supported]- Specified by:
getNetworkTimeoutin interfacejava.sql.Connection
-
checkMap
static void checkMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)
Check that the given type map is either null or empty.- Parameters:
map- the type map- Throws:
DbException- if the map is not empty
-
toString
public java.lang.String toString()
INTERNAL- Overrides:
toStringin classjava.lang.Object
-
getCompareMode
CompareMode getCompareMode()
-
getMode
public Mode getMode()
Description copied from interface:CastDataProviderReturns the database mode.- Specified by:
getModein interfaceCastDataProvider- Returns:
- the database mode
-
getStaticSettings
public Session.StaticSettings getStaticSettings()
INTERNAL- Returns:
- StaticSettings
-
currentTimestamp
public ValueTimestampTimeZone currentTimestamp()
Description copied from interface:CastDataProviderReturns the current timestamp with maximum resolution. The value must be the same within a transaction or within execution of a command.- Specified by:
currentTimestampin interfaceCastDataProvider- Returns:
- the current timestamp for CURRENT_TIMESTAMP(9)
-
currentTimeZone
public TimeZoneProvider currentTimeZone()
Description copied from interface:CastDataProviderReturns the current time zone.- Specified by:
currentTimeZonein interfaceCastDataProvider- Returns:
- the current time zone
-
getJavaObjectSerializer
public JavaObjectSerializer getJavaObjectSerializer()
Description copied from interface:CastDataProviderReturns the custom Java object serializer, ornull.- Specified by:
getJavaObjectSerializerin interfaceCastDataProvider- Returns:
- the custom Java object serializer, or
null
-
zeroBasedEnums
public boolean zeroBasedEnums()
Description copied from interface:CastDataProviderReturns are ENUM values 0-based.- Specified by:
zeroBasedEnumsin interfaceCastDataProvider- Returns:
- are ENUM values 0-based
-
-