A JDBC Connection
. For documentation of this class, see java.sql.Connection
.
Methods
Detailed documentation
clearWarnings()
For documentation of this method, see java.sql.Connection#clearWarnings()
.
close()
Release the JdbcConnection's database and all associated resources.
var conn = Jdbc.getConnection("jdbc:mysql://<host>:<port>/<instance>", "user", "password");
conn.close();
See also
commit()
Makes all pending changes permanent, releases database locks held by this JdbcConnection.
var conn = Jdbc.getConnection("jdbc:mysql://<host>:<port>/<instance>", "user", "password");
conn.setAutoCommit(false);
var stmt = conn.prepareStatement("insert into person (lname,fname) values (?,?)");
var start = new Date();
for (var i = 0; i < 5000; i++) {
// Objects are accessed using 1-based indexing
stmt.setObject(1, 'firstName' + i);
stmt.setObject(2, 'lastName' + i);
stmt.addBatch();
}
var res = stmt.executeBatch();
conn.commit(); // When this returns, this is when changes are actually commited
conn.close();
See also
createArrayOf(typeName, elements)
For documentation of this method, see
java.sql.Connection#createArrayOf(String, Object[])
.
Parameters
Name | Type | Description |
---|---|---|
typeName | String | |
elements | Object[] |
Return
createBlob()
Constructs a JdbcBlob
instance
The object returned initially contains no data. The setBytes methods of JdbcBlob
may
be used to set the data it should contain. Note that the blob used here is not the same
as the blob created with
Utilities.newBlob(data)
. To
convert between the two formats, use the defined getBytes() and setBytes() methods.
Alternatively, both JdbcBlob
and JdbcClob
provide a getAppsScriptBlob()
convenience method for converting to a format that can be used by Apps Script.
Return
See also
createStatement()
Creates a JdbcStatement object for sending SQL statements to the database.
// This sample code assumes authentication is off
var conn = Jdbc.getConnection("jdbc:mysql://<host>:3306/<instance>")
var stmt = conn.createStatement();
stmt.setMaxRows(100);
var rs = stmt.execute("select * from person");
while(rs.next()) {
// Do something
}
rs.close();
stmt.close();
conn.close();
Return
JdbcStatement
— a JdbcStatement
instance to execute queries with
See also
createStatement(resultSetType, resultSetConcurrency)
Creates a JdbcStatement object for sending SQL statements to the database. 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)
var conn = Jdbc.getConnection("jdbc:mysql://<host>:3306/<instance>")
var stmt = conn.createStatement(Jdbc.ResultSet.TYPE_FORWARD_ONLY,
Jdbc.ResultSet.CONCUR_READ_ONLY);
stmt.setMaxRows(100);
var rs = stmt.execute("select * from person");
while(rs.next()) {
// Do something
}
rs.close();
stmt.close();
conn.close();
Parameters
Name | Type | Description |
---|---|---|
resultSetType | Integer | a result set type; one of Jdbc.ResultSet.TYPE_FORWARD_ONLY, Jdbc.ResultSet.TYPE_SCROLL_INSENSITIVE, or Jdbc.ResultSet.TYPE_SCROLL_SENSITIVE |
resultSetConcurrency | Integer | a concurrency type; one of Jdbc.ResultSet.CONCUR_READ_ONLY or Jdbc.ResultSet.CONCUR_UPDATABLE |
Return
JdbcStatement
— a JdbcStatement
instance to execute queries with
See also
createStatement(resultSetType, resultSetConcurrency, resultSetHoldability)
Creates a JdbcStatement object for sending SQL statements to the database. 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)
var conn = Jdbc.getConnection("jdbc:mysql://<host>:3306/<instance>")
var stmt = conn.createStatement(Jdbc.ResultSet.TYPE_FORWARD_ONLY,
Jdbc.ResultSet.CONCUR_READ_ONLY,
Jdbc.ResultSet.HOLD_CURSORS_OVER_COMMIT);
stmt.setMaxRows(100);
var rs = stmt.execute("select * from person");
while(rs.next()) {
// Do something
}
rs.close();
stmt.close();
conn.close();
Parameters
Name | Type | Description |
---|---|---|
resultSetType | Integer | a result set type; one of Jdbc.ResultSet.TYPE_FORWARD_ONLY, Jdbc.ResultSet.TYPE_SCROLL_INSENSITIVE, or Jdbc.ResultSet.TYPE_SCROLL_SENSITIVE |
resultSetConcurrency | Integer | a concurrency type; one of Jdbc.ResultSet.CONCUR_READ_ONLY or Jdbc.ResultSet.CONCUR_UPDATABLE |
resultSetHoldability | Integer | a Jdbc.ResultSet holdability constant; one of Jdbc.ResultSet.HOLD_CURSORS_OVER_COMMIT or Jdbc.ResultSet.CLOSE_CURSORS_AT_COMMIT |
Return
JdbcStatement
— a JdbcStatement
instance to execute queries with
See also
createStruct(typeName, attributes)
For documentation of this method, see
java.sql.Connection#createStruct(String, Object[])
.
Parameters
Name | Type | Description |
---|---|---|
typeName | String | |
attributes | Object[] |
Return
getAutoCommit()
For documentation of this method, see java.sql.Connection#getAutoCommit()
.
Return
Boolean
getHoldability()
For documentation of this method, see java.sql.Connection#getHoldability()
.
Return
Integer
getTransactionIsolation()
For documentation of this method, see java.sql.Connection#getTransactionIsolation()
.
Return
Integer
getWarnings()
For documentation of this method, see java.sql.Connection#getWarnings()
.
Return
String[]
isValid(timeout)
For documentation of this method, see java.sql.Connection#isValid(int)
.
Parameters
Name | Type | Description |
---|---|---|
timeout | Integer |
Return
Boolean
nativeSQL(sql)
For documentation of this method, see java.sql.Connection#nativeSQL(String)
.
Parameters
Name | Type | Description |
---|---|---|
sql | String |
Return
String
prepareCall(sql)
For documentation of this method, see java.sql.Connection#prepareCall(String)
.
Parameters
Name | Type | Description |
---|---|---|
sql | String |
Return
prepareCall(sql, resultSetType, resultSetConcurrency)
For documentation of this method, see
java.sql.Connection#prepareCall(String, int, int)
.
Parameters
Name | Type | Description |
---|---|---|
sql | String | |
resultSetType | Integer | |
resultSetConcurrency | Integer |
Return
prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability)
For documentation of this method, see
java.sql.Connection#prepareCall(String, int, int, int)
.
Parameters
Name | Type | Description |
---|---|---|
sql | String | |
resultSetType | Integer | |
resultSetConcurrency | Integer | |
resultSetHoldability | Integer |
Return
prepareStatement(sql)
For documentation of this method, see java.sql.Connection#prepareStatement(String)
.
Parameters
Name | Type | Description |
---|---|---|
sql | String |
Return
prepareStatement(sql, autoGeneratedKeys)
For documentation of this method, see
java.sql.Connection#prepareStatement(String, int)
.
Parameters
Name | Type | Description |
---|---|---|
sql | String | |
autoGeneratedKeys | Integer |
Return
prepareStatement(sql, resultSetType, resultSetConcurrency)
For documentation of this method, see
java.sql.Connection#prepareStatement(String, int, int)
.
Parameters
Name | Type | Description |
---|---|---|
sql | String | |
resultSetType | Integer | |
resultSetConcurrency | Integer |
Return
prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)
For documentation of this method, see
java.sql.Connection#prepareStatement(String, int, int, int)
.
Parameters
Name | Type | Description |
---|---|---|
sql | String | |
resultSetType | Integer | |
resultSetConcurrency | Integer | |
resultSetHoldability | Integer |
Return
prepareStatementByIndex(sql, indices)
For documentation of this method, see
java.sql.Connection#prepareStatement(String, int[])
.
Parameters
Name | Type | Description |
---|---|---|
sql | String | |
indices | Integer[] |
Return
prepareStatementByName(sql, columnNames)
For documentation of this method, see
java.sql.Connection#prepareStatement(String, String[])
.
Parameters
Name | Type | Description |
---|---|---|
sql | String | |
columnNames | String[] |
Return
releaseSavepoint(savepoint)
For documentation of this method, see
java.sql.Connection#releaseSavepoint(java.sql.Savepoint)
.
Parameters
Name | Type | Description |
---|---|---|
savepoint | JdbcSavepoint |
rollback()
For documentation of this method, see java.sql.Connection#rollback()
.
rollback(savepoint)
For documentation of this method, see
java.sql.Connection#rollback(java.sql.Savepoint)
.
Parameters
Name | Type | Description |
---|---|---|
savepoint | JdbcSavepoint |
setAutoCommit(autoCommit)
For documentation of this method, see java.sql.Connection#setAutoCommit(boolean)
.
Parameters
Name | Type | Description |
---|---|---|
autoCommit | Boolean |
setCatalog(catalog)
For documentation of this method, see java.sql.Connection#setCatalog(String)
.
Parameters
Name | Type | Description |
---|---|---|
catalog | String |
setHoldability(holdability)
For documentation of this method, see java.sql.Connection#setHoldability(int)
.
Parameters
Name | Type | Description |
---|---|---|
holdability | Integer |
setReadOnly(readOnly)
For documentation of this method, see java.sql.Connection#setReadOnly(boolean)
.
Parameters
Name | Type | Description |
---|---|---|
readOnly | Boolean |
setSavepoint(name)
For documentation of this method, see java.sql.Connection#setSavepoint(String)
.
Parameters
Name | Type | Description |
---|---|---|
name | String |
Return
setTransactionIsolation(level)
For documentation of this method, see
java.sql.Connection#setTransactionIsolation(int)
.
Parameters
Name | Type | Description |
---|---|---|
level | Integer |