Jdbc

The JDBC service allows scripts to connect to [Google Cloud SQL](https://developers.google.com/cloud-sql), MySQL,
Microsoft SQL Server, Oracle, and PostgreSQL databases. For more information, see the [guide to JDBC](https://developers.google.com/apps-script/guides/jdbc).

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#getCloudSqlConnection(String)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` | Attempts to establish a connection to the given Google Cloud SQL URL. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#getCloudSqlConnection(String,Object)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` | Attempts to establish a connection to the given Google Cloud SQL URL. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#getCloudSqlConnection(String,String,String)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` | Attempts to establish a connection to the given Google Cloud SQL URL. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#getConnection(String)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` | Attempts to establish a connection to the given database URL. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#getConnection(String,Object)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` | Attempts to establish a connection to the given database URL. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#getConnection(String,String,String)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` | Attempts to establish a connection to the given database using a username and password. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#newDate(Integer)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-date` | Create a date from milliseconds since epoch. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#newTime(Integer)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-time` | Create a time from milliseconds since epoch. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#newTimestamp(Integer)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-timestamp` | Create a timestamp from milliseconds since epoch. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#parseDate(String)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-date` | Create a date by parsing the SQL date string. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#parseTime(String)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-time` | Create a time by parsing the SQL time string. |
| `https://developers.google.com/apps-script/reference/jdbc/jdbc#parseTimestamp(String)` | `https://developers.google.com/apps-script/reference/jdbc/jdbc-timestamp` | 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 form `jdbc:google:mysql://subname`. |

#### Return


`https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` --- A JdbcConnection object.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `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 form `jdbc:google:mysql://subname`. |
| `info` | `Object` | Optional JavaScript object specifying advanced parameters as defined below. |

#### Advanced parameters

| Name | Type | Description |
|---|---|---|
| `connectTimeoutSeconds` | `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 |
| `queryTimeoutSeconds` | `Integer` | query timeout in seconds |
| `user` | `String` | the username to pass to the database |

#### Return


`https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` --- A JdbcConnection object.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `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 form `jdbc:google:mysql://subname`. |
| `userName` | `String` | The username to pass to the database. |
| `password` | `String` | The user's password. |

#### Return


`https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` --- A JdbcConnection object.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/sqlservice`

*** ** * ** ***

### `getConnection(url)`

Attempts to establish a connection to the given database URL.

```javascript
const conn = Jdbc.getConnection(
    'jdbc:mysql://yoursqlserver.example.com:3306/database_name',
);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `url` | `String` | A database URL of the form `jdbc:subprotocol:subname`. |

#### Return


`https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` --- A JdbcConnection object.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/script.external_request`

*** ** * ** ***

### `getConnection(url, info)`

Attempts to establish a connection to the given database URL.

```javascript
const conn = 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 form `jdbc:subprotocol:subname`. |
| `info` | `Object` | Optional JavaScript object specifying advanced parameters as defined below. |

#### Advanced parameters

| Name | Type | Description |
|---|---|---|
| `databaseName` | `String` | the database to connect to |
| `password` | `String` | the user's password |
| `useJDBCCompliantTimeZoneShift` | `Boolean` | whether or not the connection should comply with JDBC rules when converting time zones. The default is `false`. |
| `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


`https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` --- A JdbcConnection object.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `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.

```javascript
const conn = Jdbc.getConnection(
    'jdbc:mysql://yoursqlserver.example.com:3306/database_name',
    'username',
    'password',
);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `url` | `String` | A database URL of the form `jdbc:subprotocol:subname`. |
| `userName` | `String` | The username to pass to the database. |
| `password` | `String` | The user's password. |

#### Return


`https://developers.google.com/apps-script/reference/jdbc/jdbc-connection` --- A JdbcConnection object.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `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


`https://developers.google.com/apps-script/reference/jdbc/jdbc-date` --- A JdbcDate object.

*** ** * ** ***

### `newTime(milliseconds)`

Create a time from milliseconds since epoch.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `milliseconds` | `Integer` | Milliseconds since epoch. |

#### Return


`https://developers.google.com/apps-script/reference/jdbc/jdbc-time` --- A JdbcTime object.

*** ** * ** ***

### `newTimestamp(milliseconds)`

Create a timestamp from milliseconds since epoch.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `milliseconds` | `Integer` | Milliseconds since epoch. |

#### Return


`https://developers.google.com/apps-script/reference/jdbc/jdbc-timestamp` --- 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


`https://developers.google.com/apps-script/reference/jdbc/jdbc-date` --- 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


`https://developers.google.com/apps-script/reference/jdbc/jdbc-time` --- 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


`https://developers.google.com/apps-script/reference/jdbc/jdbc-timestamp` --- A JdbcTimestamp object.