Class JdbcConnection

  • A JdbcConnection is a JDBCConnection object used to interact with a database.

  • It provides methods to manage the connection, such as closing it, committing or rolling back transactions, and setting properties like auto-commit and read-only modes.

  • The class includes methods for creating various types of SQL statements (Statement, PreparedStatement, CallableStatement) and objects like Arrays, Blobs, Clobs, and SQLXML.

  • Methods are available to retrieve information about the connection and the database metadata, as well as handle warnings.

JdbcConnection

A JDBCConnection. For documentation of this class, seejava.sql.Connection.

Methods

MethodReturn typeBrief description
clearWarnings()voidFor documentation of this method, seejava.sql.Connection#clearWarnings().
close()voidRelease this connection's database and all associated resources.
commit()voidMakes all pending changes permanent, releases database locks held by thisJdbcConnection.
createArrayOf(typeName, elements)JdbcArrayFor documentation of this method, seejava.sql.Connection#createArrayOf(String, Object[]).
createBlob()JdbcBlobConstructs aJdbcBlob instance.
createClob()JdbcClobFor documentation of this method, seejava.sql.Connection#createClob().
createNClob()JdbcClobFor documentation of this method, seejava.sql.Connection#createNClob().
createSQLXML()JdbcSQLXMLFor documentation of this method, seejava.sql.Connection#createSQLXML().
createStatement()JdbcStatementCreates aJdbcStatement object for sending SQL statements to the database.
createStatement(resultSetType, resultSetConcurrency)JdbcStatementCreates aJdbcStatement object for sending SQL statements to the database.
createStatement(resultSetType, resultSetConcurrency, resultSetHoldability)JdbcStatementCreates aJdbcStatement object for sending SQL statements to the database.
createStruct(typeName, attributes)JdbcStructFor documentation of this method, seejava.sql.Connection#createStruct(String, Object[]).
getAutoCommit()BooleanFor documentation of this method, seejava.sql.Connection#getAutoCommit().
getCatalog()Stringor documentation of this method, seejava.sql.Connection#getCatalog().
getHoldability()IntegerFor documentation of this method, seejava.sql.Connection#getHoldability().
getMetaData()JdbcDatabaseMetaDataFor documentation of this method, seejava.sql.Connection#getMetaData().
getTransactionIsolation()IntegerFor documentation of this method, seejava.sql.Connection#getTransactionIsolation().
getWarnings()String[]For documentation of this method, seejava.sql.Connection#getWarnings().
isClosed()BooleanFor documentation of this method, seejava.sql.Connection#isClosed().
isReadOnly()BooleanFor documentation of this method, seejava.sql.Connection#isReadOnly().
isValid(timeout)BooleanFor documentation of this method, seejava.sql.Connection#isValid(int).
nativeSQL(sql)StringFor documentation of this method, seejava.sql.Connection#nativeSQL(String).
prepareCall(sql)JdbcCallableStatementFor documentation of this method, seejava.sql.Connection#prepareCall(String).
prepareCall(sql, resultSetType, resultSetConcurrency)JdbcCallableStatementFor documentation of this method, seejava.sql.Connection#prepareCall(String, int, int).
prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability)JdbcCallableStatementFor documentation of this method, seejava.sql.Connection#prepareCall(String, int, int, int).
prepareStatement(sql)JdbcPreparedStatementFor documentation of this method, seejava.sql.Connection#prepareStatement(String).
prepareStatement(sql, autoGeneratedKeys)JdbcPreparedStatementFor documentation of this method, seejava.sql.Connection#prepareStatement(String, int).
prepareStatement(sql, resultSetType, resultSetConcurrency)JdbcPreparedStatementFor documentation of this method, seejava.sql.Connection#prepareStatement(String, int, int).
prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)JdbcPreparedStatementFor documentation of this method, seejava.sql.Connection#prepareStatement(String, int, int, int).
prepareStatementByIndex(sql, indices)JdbcPreparedStatementFor documentation of this method, seejava.sql.Connection#prepareStatement(String, int[]).
prepareStatementByName(sql, columnNames)JdbcPreparedStatementFor documentation of this method, seejava.sql.Connection#prepareStatement(String, String[]).
releaseSavepoint(savepoint)voidFor documentation of this method, seejava.sql.Connection#releaseSavepoint(Savepoint).
rollback()voidFor documentation of this method, seejava.sql.Connection#rollback().
rollback(savepoint)voidFor documentation of this method, seejava.sql.Connection#rollback(Savepoint).
setAutoCommit(autoCommit)voidFor documentation of this method, seejava.sql.Connection#setAutoCommit(boolean).
setCatalog(catalog)voidFor documentation of this method, seejava.sql.Connection#setCatalog(String).
setHoldability(holdability)voidFor documentation of this method, seejava.sql.Connection#setHoldability(int).
setReadOnly(readOnly)voidFor documentation of this method, seejava.sql.Connection#setReadOnly(boolean).
setSavepoint()JdbcSavepointFor documentation of this method, seejava.sql.Connection#setSavepoint().
setSavepoint(name)JdbcSavepointFor documentation of this method, seejava.sql.Connection#setSavepoint(String).
setTransactionIsolation(level)voidFor documentation of this method, seejava.sql.Connection#setTransactionIsolation(int).

Detailed documentation

clearWarnings()

For documentation of this method, seejava.sql.Connection#clearWarnings().

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

close()

Release this connection's database and all associated resources.

constconn=Jdbc.getConnection('jdbc:mysql://<host>:<port>/<instance>','user','password',);conn.close();

See also

  • Connection.close()

commit()

Makes all pending changes permanent, releases database locks held by thisJdbcConnection.

constconn=Jdbc.getConnection('jdbc:mysql://<host>:<port>/<instance>','user','password',);conn.setAutoCommit(false);conststmt=conn.prepareStatement('insert into person (lname,fname) values (?,?)',);conststart=newDate();for(leti=0;i <5000;i++){// Objects are accessed using 1-based indexingstmt.setObject(1,`firstName${i}`);stmt.setObject(2,`lastName${i}`);stmt.addBatch();}constres=stmt.executeBatch();conn.commit();// When this returns, this is when changes are actually// committedconn.close();

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

See also

  • Connection.commit()

createArrayOf(typeName, elements)

For documentation of this method, seejava.sql.Connection#createArrayOf(String, Object[]).

Parameters

NameTypeDescription
typeNameStringThe database-specific SQL name of the array elemnents' type. Options include built-in types, user-defined types, or standard SQL types supported by the database.
elementsObject[]The elements to populate in the returned object.

Return

JdbcArray — An array whose elements map to the specified SQL type.


createBlob()

Constructs aJdbcBlob instance. See alsojava.sql.Connection#createBlob().

The object returned initially contains no data. You can use thesetBytes methods ofJdbcBlob to set the data it should contain. The blob used here is not the same as theblob created withUtilities.newBlob(data). To convertbetween the two formats, use the definedgetBytes() andsetBytes() methods.Alternatively, bothJdbcBlob andJdbcClob provide agetAppsScriptBlob()convenience method for converting to a format that can be used by Apps Script.

Return

JdbcBlob — An empty blob object.


createClob()

For documentation of this method, seejava.sql.Connection#createClob().

Return

JdbcClob — An empty clob object.


createNClob()

For documentation of this method, seejava.sql.Connection#createNClob().

Return

JdbcClob — An empty nclob object.


createSQLXML()

For documentation of this method, seejava.sql.Connection#createSQLXML().

Return

JdbcSQLXML — An empty SQLXML object.


createStatement()

Creates aJdbcStatement object for sending SQL statements to the database. See alsojava.sql.Connection#createStatement().

// This sample code assumes authentication is offconstconn=Jdbc.getConnection('jdbc:mysql://<host>:3306/<instance>');conststmt=conn.createStatement();stmt.setMaxRows(100);constrs=stmt.execute('select * from person');while(rs.next()){// Do something}rs.close();stmt.close();conn.close();

Return

JdbcStatement — A statement instance to execute queries with.


createStatement(resultSetType, resultSetConcurrency)

Creates aJdbcStatement object for sending SQL statements to the database. See alsojava.sql.Connection#createStatement(int, int).

This version allows the result set type and concurrency to be overridden.

// This sample code assumes authentication is off// For more information about this method, see documentation here://  http://docs.oracle.com/javase/6/docs/api/java/sql/Connection.html#createStatement(int,//  int)constconn=Jdbc.getConnection('jdbc:mysql://<host>:3306/<instance>');conststmt=conn.createStatement(Jdbc.ResultSet.TYPE_FORWARD_ONLY,Jdbc.ResultSet.CONCUR_READ_ONLY,);stmt.setMaxRows(100);constrs=stmt.execute('select * from person');while(rs.next()){// Do something}rs.close();stmt.close();conn.close();

Parameters

NameTypeDescription
resultSetTypeIntegerA result set type; one ofJdbc.ResultSet.TYPE_FORWARD_ONLY,Jdbc.ResultSet.TYPE_SCROLL_INSENSITIVE, orJdbc.ResultSet.TYPE_SCROLL_SENSITIVE.
resultSetConcurrencyIntegerA concurrency type; eitherJdbc.ResultSet.CONCUR_READ_ONLY orJdbc.ResultSet.CONCUR_UPDATABLE.

Return

JdbcStatement — A statement instance to execute queries with.


createStatement(resultSetType, resultSetConcurrency, resultSetHoldability)

Creates aJdbcStatement object for sending SQL statements to the database. See alsojava.sql.Connection#createStatement(int, int, int).

This version allows the result set type, concurrency and holdability to be overridden.

// This sample code assumes authentication is off// For more information about this method, see documentation here://  http://docs.oracle.com/javase/6/docs/api/java/sql/Connection.html#createStatement(int,//  int)constconn=Jdbc.getConnection('jdbc:mysql://<host>:3306/<instance>');conststmt=conn.createStatement(Jdbc.ResultSet.TYPE_FORWARD_ONLY,Jdbc.ResultSet.CONCUR_READ_ONLY,Jdbc.ResultSet.HOLD_CURSORS_OVER_COMMIT,);stmt.setMaxRows(100);constrs=stmt.execute('select * from person');while(rs.next()){// Do something}rs.close();stmt.close();conn.close();

Parameters

NameTypeDescription
resultSetTypeIntegerA result set type; one ofJdbc.ResultSet.TYPE_FORWARD_ONLY,Jdbc.ResultSet.TYPE_SCROLL_INSENSITIVE, orJdbc.ResultSet.TYPE_SCROLL_SENSITIVE.
resultSetConcurrencyIntegerA concurrency type; eitherJdbc.ResultSet.CONCUR_READ_ONLY orJdbc.ResultSet.CONCUR_UPDATABLE.
resultSetHoldabilityIntegerA holdability setting; eitherJdbc.ResultSet.HOLD_CURSORS_OVER_COMMIT orJdbc.ResultSet.CLOSE_CURSORS_AT_COMMIT.

Return

JdbcStatement — A statement instance to execute queries with.


createStruct(typeName, attributes)

For documentation of this method, seejava.sql.Connection#createStruct(String, Object[]).

Parameters

NameTypeDescription
typeNameStringThe database-specific SQL name of the array elemnents' type. Options include built-in types, user-defined types, or standard SQL types supported by the database.
attributesObject[]The attributes that populate the returned object.

Return

JdbcStruct — A structure object that maps to the given SQL type and is populated with the given attributes.


getAutoCommit()

For documentation of this method, seejava.sql.Connection#getAutoCommit().

Return

Booleantrue if the connection's auto-commit mode is enabled;false otherwise.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

getCatalog()

or documentation of this method, seejava.sql.Connection#getCatalog().

Return

String — The current catalog name ornull if no name has been set.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

getHoldability()

For documentation of this method, seejava.sql.Connection#getHoldability().

Return

Integer — The holdability setting of the connection; eitherJdbc.ResultSet.HOLD_CURSORS_OVER_COMMIT orJdbc.ResultSet.CLOSE_CURSORS_AT_COMMIT.


getMetaData()

For documentation of this method, seejava.sql.Connection#getMetaData().

Return

JdbcDatabaseMetaData — The metadata of the database this connection connects to.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

getTransactionIsolation()

For documentation of this method, seejava.sql.Connection#getTransactionIsolation().

Return

Integer — The current transaction level, which is one of:Jdbc.Connection.TRANSACTION_READ_UNCOMMITTED,Jdbc.Connection.TRANSACTION_READ_COMMITTED,Jdbc.Connection.TRANSACTION_REPEATABLE_READ,Jdbc.Connection.TRANSACTION_SERIALIZABLE, orJdbc.Connection.TRANSACTION_NONE.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

getWarnings()

For documentation of this method, seejava.sql.Connection#getWarnings().

Return

String[] — An array of warning strings.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

isClosed()

For documentation of this method, seejava.sql.Connection#isClosed().

Return

Booleantrue if the connection is closed;false otherwise.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

isReadOnly()

For documentation of this method, seejava.sql.Connection#isReadOnly().

Return

Booleantrue if the connection is read-only;false otherwise.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

isValid(timeout)

For documentation of this method, seejava.sql.Connection#isValid(int).

Parameters

NameTypeDescription
timeoutIntegerThe time in seconds to wait for the validation operation to complete. A value of 0 indicates no timeout is applied.

Return

Booleantrue if the connection is valid;false otherwise. Also returnsfalse if the timeout period expires before the operation completes.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

nativeSQL(sql)

For documentation of this method, seejava.sql.Connection#nativeSQL(String).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' placeholders.

Return

String — The native form of the provided statement.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

prepareCall(sql)

For documentation of this method, seejava.sql.Connection#prepareCall(String).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' placeholders, typically provided using JDBC call escape syntax.

Return

JdbcCallableStatement — A callable statement containing the pre-compiled SQL statement.


prepareCall(sql, resultSetType, resultSetConcurrency)

For documentation of this method, seejava.sql.Connection#prepareCall(String, int, int).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' placeholders, typically provided using JDBC call escape syntax.
resultSetTypeIntegerA result set type; one ofJdbc.ResultSet.TYPE_FORWARD_ONLY,Jdbc.ResultSet.TYPE_SCROLL_INSENSITIVE, orJdbc.ResultSet.TYPE_SCROLL_SENSITIVE.
resultSetConcurrencyIntegerA concurrency type; eitherJdbc.ResultSet.CONCUR_READ_ONLY orJdbc.ResultSet.CONCUR_UPDATABLE.

Return

JdbcCallableStatement — A callable statement containing the pre-compiled SQL statement that produces result sets with the provided type and concurrency.


prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability)

For documentation of this method, seejava.sql.Connection#prepareCall(String, int, int, int).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' placeholders, typically provided using JDBC call escape syntax.
resultSetTypeIntegerA result set type; one ofJdbc.ResultSet.TYPE_FORWARD_ONLY,Jdbc.ResultSet.TYPE_SCROLL_INSENSITIVE, orJdbc.ResultSet.TYPE_SCROLL_SENSITIVE.
resultSetConcurrencyIntegerA concurrency type; eitherJdbc.ResultSet.CONCUR_READ_ONLY orJdbc.ResultSet.CONCUR_UPDATABLE.
resultSetHoldabilityIntegerA holdability setting; eitherJdbc.ResultSet.HOLD_CURSORS_OVER_COMMIT orJdbc.ResultSet.CLOSE_CURSORS_AT_COMMIT.

Return

JdbcCallableStatement — A callable statement containing the pre-compiled SQL statement that produces result sets with the provided type, concurrency.


prepareStatement(sql)

For documentation of this method, seejava.sql.Connection#prepareStatement(String).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' IN parameter placeholders.

Return

JdbcPreparedStatement — A prepared statement containing the pre-compiled SQL statement.


prepareStatement(sql, autoGeneratedKeys)

For documentation of this method, seejava.sql.Connection#prepareStatement(String, int).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' IN parameter placeholders.
autoGeneratedKeysIntegerA flag that indicates whether auto-generated keys are returned; eitherJdbc.Statement.RETURN_GENERATED_KEYS orJdbc.Statement.NO_GENERATED_KEYS.

Return

JdbcPreparedStatement — A prepared statement containing the pre-compiled SQL statement, possibly capable of returning auto-generated keys.


prepareStatement(sql, resultSetType, resultSetConcurrency)

For documentation of this method, seejava.sql.Connection#prepareStatement(String, int, int).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' IN parameter placeholders.
resultSetTypeIntegerA result set type; one ofJdbc.ResultSet.TYPE_FORWARD_ONLY,Jdbc.ResultSet.TYPE_SCROLL_INSENSITIVE, orJdbc.ResultSet.TYPE_SCROLL_SENSITIVE.
resultSetConcurrencyIntegerA concurrency type; eitherJdbc.ResultSet.CONCUR_READ_ONLY orJdbc.ResultSet.CONCUR_UPDATABLE.

Return

JdbcPreparedStatement — A prepared statement containing the pre-compiled SQL statement that produces result sets with the provided type and concurrency.


prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)

For documentation of this method, seejava.sql.Connection#prepareStatement(String, int, int, int).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' IN parameter placeholders.
resultSetTypeIntegerA result set type; one ofJdbc.ResultSet.TYPE_FORWARD_ONLY,Jdbc.ResultSet.TYPE_SCROLL_INSENSITIVE, orJdbc.ResultSet.TYPE_SCROLL_SENSITIVE.
resultSetConcurrencyIntegerA concurrency type; eitherJdbc.ResultSet.CONCUR_READ_ONLY orJdbc.ResultSet.CONCUR_UPDATABLE.
resultSetHoldabilityIntegerA holdability setting; eitherJdbc.ResultSet.HOLD_CURSORS_OVER_COMMIT orJdbc.ResultSet.CLOSE_CURSORS_AT_COMMIT.

Return

JdbcPreparedStatement — A prepared statement containing the pre-compiled SQL statement that produces result sets with the provided type, concurrency, and holdability.


prepareStatementByIndex(sql, indices)

For documentation of this method, seejava.sql.Connection#prepareStatement(String, int[]).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' IN parameter placeholders.
indicesInteger[]The column indices of columns that are returned from the inserted row or rows.

Return

JdbcPreparedStatement — A prepared statement containing the pre-compiled SQL statement, capable of returning auto-generated keys specified by the provided column indices.


prepareStatementByName(sql, columnNames)

For documentation of this method, seejava.sql.Connection#prepareStatement(String, String[]).

Parameters

NameTypeDescription
sqlStringAn SQL statement that may contain one more more '?' IN parameter placeholders.
columnNamesString[]The column names that specify which columns the method should return from the inserted row or rows.

Return

JdbcPreparedStatement — A prepared statement containing the pre-compiled SQL statement, capable of returning auto-generated keys specified by the provided column names.


releaseSavepoint(savepoint)

For documentation of this method, seejava.sql.Connection#releaseSavepoint(Savepoint).

Parameters

NameTypeDescription
savepointJdbcSavepointThe save point to remove.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

rollback()

For documentation of this method, seejava.sql.Connection#rollback().

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

rollback(savepoint)

For documentation of this method, seejava.sql.Connection#rollback(Savepoint).

Parameters

NameTypeDescription
savepointJdbcSavepointThe save point to rollback to.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

setAutoCommit(autoCommit)

For documentation of this method, seejava.sql.Connection#setAutoCommit(boolean).

Parameters

NameTypeDescription
autoCommitBooleanIftrue, auto-commit mode is enabled;false disables.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

setCatalog(catalog)

For documentation of this method, seejava.sql.Connection#setCatalog(String).

Parameters

NameTypeDescription
catalogStringThe name of a catalog (the subspace in the connection's database) in which to work.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

setHoldability(holdability)

For documentation of this method, seejava.sql.Connection#setHoldability(int).

Parameters

NameTypeDescription
holdabilityIntegerThe default holdability ofJdbcResultSet objects created with this connection; eitherJdbc.ResultSet.HOLD_CURSORS_OVER_COMMIT orJdbc.ResultSet.CLOSE_CURSORS_AT_COMMIT.

setReadOnly(readOnly)

For documentation of this method, seejava.sql.Connection#setReadOnly(boolean).

Parameters

NameTypeDescription
readOnlyBooleanIftrue, read-only mode is enabled;false disables.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

setSavepoint()

For documentation of this method, seejava.sql.Connection#setSavepoint().

Return

JdbcSavepoint — The new unnamed save point.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

setSavepoint(name)

For documentation of this method, seejava.sql.Connection#setSavepoint(String).

Parameters

NameTypeDescription
nameStringThe name of the created save point.

Return

JdbcSavepoint — The new named save point.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

setTransactionIsolation(level)

For documentation of this method, seejava.sql.Connection#setTransactionIsolation(int).

Parameters

NameTypeDescription
levelIntegerThe transaction level to set, which is one of:Jdbc.Connection.TRANSACTION_READ_UNCOMMITTED,Jdbc.Connection.TRANSACTION_READ_COMMITTED,Jdbc.Connection.TRANSACTION_REPEATABLE_READ,Jdbc.Connection.TRANSACTION_SERIALIZABLE, orJdbc.Connection.TRANSACTION_NONE.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/script.external_request

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.