Class Jdbc

  • The JDBC service enables scripts to connect to various databases including Google Cloud SQL, MySQL, Microsoft SQL Server, and Oracle.

  • ThegetConnection andgetCloudSqlConnection methods are used to establish database connections using a URL, with optional parameters for user credentials and advanced settings.

  • The service provides methods likenewDate,newTime,newTimestamp, and their correspondingparse methods to handle date and time values.

Jdbc

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

MethodReturn typeBrief description
getCloudSqlConnection(url)JdbcConnectionAttempts to establish a connection to the given Google Cloud SQL URL.
getCloudSqlConnection(url, info)JdbcConnectionAttempts to establish a connection to the given Google Cloud SQL URL.
getCloudSqlConnection(url, userName, password)JdbcConnectionAttempts to establish a connection to the given Google Cloud SQL URL.
getConnection(url)JdbcConnectionAttempts to establish a connection to the given database URL.
getConnection(url, info)JdbcConnectionAttempts to establish a connection to the given database URL.
getConnection(url, userName, password)JdbcConnectionAttempts to establish a connection to the given database using a username and password.
newDate(milliseconds)JdbcDateCreate a date from milliseconds since epoch.
newTime(milliseconds)JdbcTimeCreate a time from milliseconds since epoch.
newTimestamp(milliseconds)JdbcTimestampCreate a timestamp from milliseconds since epoch.
parseDate(date)JdbcDateCreate a date by parsing the SQL date string.
parseTime(time)JdbcTimeCreate a time by parsing the SQL time string.
parseTimestamp(timestamp)JdbcTimestampCreate 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

NameTypeDescription
urlStringA database URL of the formjdbc:google:mysql://subname.

Return

JdbcConnection — 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

NameTypeDescription
urlStringA database URL of the formjdbc:google:mysql://subname.
infoObjectOptional JavaScript object specifying advanced parameters as defined below.

Advanced parameters

NameTypeDescription
connectTimeoutSecondsIntegerconnection timeout in seconds
databaseStringthe database to connect to
instanceStringthe name of a Google SQL Service instance
passwordStringthe user's password
queryTimeoutSecondsIntegerquery timeout in seconds
userStringthe username to pass to the database

Return

JdbcConnection — 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

NameTypeDescription
urlStringA database URL of the formjdbc:google:mysql://subname.
userNameStringThe username to pass to the database.
passwordStringThe user's password.

Return

JdbcConnection — 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

NameTypeDescription
urlStringA database URL of the formjdbc:subprotocol:subname.

Return

JdbcConnection — 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

NameTypeDescription
urlStringA database URL of the formjdbc:subprotocol:subname.
infoObjectOptional JavaScript object specifying advanced parameters as defined below.

Advanced parameters

NameTypeDescription
databaseNameStringthe database to connect to
passwordStringthe user's password
useJDBCCompliantTimeZoneShiftBooleanwhether or not the connection should comply with JDBC rules when converting time zones. The default isfalse.
userStringthe username to pass to the database
_serverSslCertificateStringthe server's SSL certificate
_clientSslCertificateStringthe client's SSL certificate
_clientSslKeyStringthe client's SSL key

Return

JdbcConnection — 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

NameTypeDescription
urlStringA database URL of the formjdbc:subprotocol:subname.
userNameStringThe username to pass to the database.
passwordStringThe user's password.

Return

JdbcConnection — 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

NameTypeDescription
millisecondsIntegerMilliseconds since epoch.

Return

JdbcDate — A JdbcDate object.


newTime(milliseconds)

Create a time from milliseconds since epoch.

Parameters

NameTypeDescription
millisecondsIntegerMilliseconds since epoch.

Return

JdbcTime — A JdbcTime object.


newTimestamp(milliseconds)

Create a timestamp from milliseconds since epoch.

Parameters

NameTypeDescription
millisecondsIntegerMilliseconds since epoch.

Return

JdbcTimestamp — A JdbcTimestamp object.


parseDate(date)

Create a date by parsing the SQL date string.

Parameters

NameTypeDescription
dateStringA string containing a SQL date string.

Return

JdbcDate — A JdbcDate object.


parseTime(time)

Create a time by parsing the SQL time string.

Parameters

NameTypeDescription
timeStringA string containing a SQL time string.

Return

JdbcTime — A JdbcTime object.


parseTimestamp(timestamp)

Create a timestamp by parsing the SQL timestamp string.

Parameters

NameTypeDescription
timestampStringA string containing a SQL timestamp string.

Return

JdbcTimestamp — 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.