Class Jdbc Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The JDBC service enables scripts to connect to various databases including Google Cloud SQL, MySQL, Microsoft SQL Server, and Oracle.
The
getConnectionandgetCloudSqlConnectionmethods are used to establish database connections using a URL, with optional parameters for user credentials and advanced settings.The service provides methods like
newDate,newTime,newTimestamp, and their correspondingparsemethods to handle date and time values.
The JDBC service allows scripts to connect toGoogle Cloud SQL, MySQL,Microsoft SQL Server, and Oracle databases. For more information, see theguide to JDBC.
Methods
| Method | Return type | Brief description |
|---|---|---|
get | Jdbc | Attempts to establish a connection to the given Google Cloud SQL URL. |
get | Jdbc | Attempts to establish a connection to the given Google Cloud SQL URL. |
get | Jdbc | Attempts to establish a connection to the given Google Cloud SQL URL. |
get | Jdbc | Attempts to establish a connection to the given database URL. |
get | Jdbc | Attempts to establish a connection to the given database URL. |
get | Jdbc | Attempts to establish a connection to the given database using a username and password. |
new | Jdbc | Create a date from milliseconds since epoch. |
new | Jdbc | Create a time from milliseconds since epoch. |
new | Jdbc | Create a timestamp from milliseconds since epoch. |
parse | Jdbc | Create a date by parsing the SQL date string. |
parse | Jdbc | Create a time by parsing the SQL time string. |
parse | Jdbc | Create a timestamp by parsing the SQL timestamp string. |
Detailed documentation
getCloudSqlConnection(url)
Attempts to establish a connection to the given Google Cloud SQL URL.
Parameters
| Name | Type | Description |
|---|---|---|
url | String | A database URL of the formjdbc:google:mysql://subname. |
Return
Jdbc — A JdbcConnection object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/sqlservice
getCloudSqlConnection(url, info)
Attempts to establish a connection to the given Google Cloud SQL URL.
Parameters
| Name | Type | Description |
|---|---|---|
url | String | A database URL of the formjdbc:google:mysql://subname. |
info | Object | Optional JavaScript object specifying advanced parameters as defined below. |
Advanced parameters
| Name | Type | Description |
|---|---|---|
connect | Integer | connection timeout in seconds |
database | String | the database to connect to |
instance | String | the name of a Google SQL Service instance |
password | String | the user's password |
query | Integer | query timeout in seconds |
user | String | the username to pass to the database |
Return
Jdbc — A JdbcConnection object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/sqlservice
getCloudSqlConnection(url, userName, password)
Attempts to establish a connection to the given Google Cloud SQL URL.
Parameters
| Name | Type | Description |
|---|---|---|
url | String | A database URL of the formjdbc:google:mysql://subname. |
user | String | The username to pass to the database. |
password | String | The user's password. |
Return
Jdbc — A JdbcConnection object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/sqlservice
getConnection(url)
Attempts to establish a connection to the given database URL.
constconn=Jdbc.getConnection('jdbc:mysql://yoursqlserver.example.com:3306/database_name',);
Parameters
| Name | Type | Description |
|---|---|---|
url | String | A database URL of the formjdbc:subprotocol:subname. |
Return
Jdbc — A JdbcConnection object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/script.external_request
getConnection(url, info)
Attempts to establish a connection to the given database URL.
constconn=Jdbc.getConnection('jdbc:mysql://yoursqlserver.example.com:3306/database_name',{user:'username',password:'password'},);
Parameters
| Name | Type | Description |
|---|---|---|
url | String | A database URL of the formjdbc:subprotocol:subname. |
info | Object | Optional JavaScript object specifying advanced parameters as defined below. |
Advanced parameters
| Name | Type | Description |
|---|---|---|
database | String | the database to connect to |
password | String | the user's password |
use | Boolean | whether or not the connection should comply with JDBC rules when converting time zones. The default isfalse. |
user | String | the username to pass to the database |
_serverSslCertificate | String | the server's SSL certificate |
_clientSslCertificate | String | the client's SSL certificate |
_clientSslKey | String | the client's SSL key |
Return
Jdbc — A JdbcConnection object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/script.external_request
getConnection(url, userName, password)
Attempts to establish a connection to the given database using a username and password.
constconn=Jdbc.getConnection('jdbc:mysql://yoursqlserver.example.com:3306/database_name','username','password',);
Parameters
| Name | Type | Description |
|---|---|---|
url | String | A database URL of the formjdbc:subprotocol:subname. |
user | String | The username to pass to the database. |
password | String | The user's password. |
Return
Jdbc — A JdbcConnection object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/script.external_request
newDate(milliseconds)
Create a date from milliseconds since epoch.
Parameters
| Name | Type | Description |
|---|---|---|
milliseconds | Integer | Milliseconds since epoch. |
Return
Jdbc — A JdbcDate object.
newTime(milliseconds)
Create a time from milliseconds since epoch.
Parameters
| Name | Type | Description |
|---|---|---|
milliseconds | Integer | Milliseconds since epoch. |
Return
Jdbc — A JdbcTime object.
newTimestamp(milliseconds)
Create a timestamp from milliseconds since epoch.
Parameters
| Name | Type | Description |
|---|---|---|
milliseconds | Integer | Milliseconds since epoch. |
Return
Jdbc — A JdbcTimestamp object.
parseDate(date)
Create a date by parsing the SQL date string.
Parameters
| Name | Type | Description |
|---|---|---|
date | String | A string containing a SQL date string. |
Return
Jdbc — A JdbcDate object.
parseTime(time)
Create a time by parsing the SQL time string.
Parameters
| Name | Type | Description |
|---|---|---|
time | String | A string containing a SQL time string. |
Return
Jdbc — A JdbcTime object.
parseTimestamp(timestamp)
Create a timestamp by parsing the SQL timestamp string.
Parameters
| Name | Type | Description |
|---|---|---|
timestamp | String | A string containing a SQL timestamp string. |
Return
Jdbc — A JdbcTimestamp object.
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.