A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/apps-script/jdbc below:

JDBC | Apps Script | Google for Developers

Skip to main content JDBC

Stay organized with collections Save and categorize content based on your preferences.

Note: Versions 1.0 and 1.1 of the TLS security protocol are disabled. To establish connections, use TLS 1.2 or higher.

Apps Script can connect to external databases through the JDBC service, a wrapper around the standard Java Database Connectivity technology. The JDBC service supports Google Cloud SQL for MySQL, MySQL, Microsoft SQL Server, and Oracle databases.

To update an external database with JDBC, your script must open a connection to the database and then make changes by sending SQL statements.

Google Cloud SQL databases

Google Cloud SQL lets you create relational databases that live in Google's cloud. Note that Cloud SQL might incur charges based on your usage.

You can create a Google Cloud SQL instance by following the steps listed in the Cloud SQL quickstart.

Creating Google Cloud SQL connections

There are two ways of establishing a connection with a Google Cloud SQL database using Apps Script's JDBC service:

These methods are explained below. Both are valid, but the second method requires you to authorize a set of IP ranges for access to your database.

Using Jdbc.getCloudSqlConnection(url) (recommended)

This method creates a connection to a Google Cloud SQL MySQL instance using the Jdbc.getCloudSqlConnection(url) method. The database URL has the form of jdbc:google:mysql://subname, where subname is the MySQL Instance connection name listed on the Cloud SQL instance Overview page in the Google Cloud console.

To connect to Cloud SQL SQL Server, see Jdbc.getConnection(url).

Using Jdbc.getConnection(url)

In order to use this method, you must authorize certain Classless Inter-Domain Routing (CIDR) IP address ranges so that Apps Script's servers can connect to your database. Before running your script, complete the following steps:

  1. In your Google Cloud SQL instance, authorize the IP ranges, one at at time from this data source.

  2. Copy the URL that was assigned to your database; it should have the form jdbc:mysql:subname.

Once you've authorized these IP ranges, you can create connections to your Google Cloud SQL instance using one of the Jdbc.getConnection(url) methods and the URL you copied above.

Other databases

If you already have your own MySQL, Microsoft SQL Server, or Oracle database, you can connect to it through Apps Script's JDBC service.

Creating other database connections

In order to create a database connection using the Apps Script JDBC service, in your database settings you must authorize IP ranges from this data source.

Note: The JDBC service can only connect to ports 1025 and above. Ensure your database is not serving off a lower port.

Once these allowlists are in place, you can create a connection to the database using one of the Jdbc.getConnection(url) methods and your database's URL.

Sample code

The sample code below assumes you are connecting to a Google Cloud SQL database, and creates database connections using the Jdbc.getCloudSqlConnection(url) method. For other databases you must use the Jdbc.getConnection(url) method to create database connections.

For more information on the JDBC methods, see the Java documentation for JDBC.

Create a database, user, and table

Most developers use the MySQL command-line tool to create databases, users, and tables. However, it's possible to do the same thing in Apps Script, as shown below. It's a good idea to create at least one other user so that your script doesn't always have to connect to the database as root.

Write to the database

The examples below demonstrate how to write a single record to the database as well as a batch of 500 records. Batching is vital for bulk operations.

Note also the use of parameterized statements, in which the variables are denoted by ?. To prevent SQL injection attacks, you should use parameterized statements to escape all user-supplied data.

Read from the database

This example demonstrates how to read a large number of records from the database, looping over the result set as necessary.

Closing connections

JDBC connections close automatically when a script finishes executing. (Keep in mind that a single google.script.run call counts as a complete execution, even if the HTML service page that made the call remains open.)

Nonetheless, if you know you're done with a connection, statement, or result set before the end of the script, it's a good idea to close them manually by calling JdbcConnection.close(), JdbcStatement.close(), or JdbcResultSet.close().

Showing an alert or prompt dialog also terminates any open JDBC connections. However, other showing UI elements—like custom menus or dialogs and sidebars with custom content—does not.

​Google, Google Workspace, and related marks and logos are trademarks of Google LLC. All other company and product names are trademarks of the companies with which they are associated.​

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

Last updated 2025-08-04 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-04 UTC."],[[["Apps Script connects to external databases (Google Cloud SQL, MySQL, SQL Server, Oracle) through the JDBC service, enabling data updates via SQL statements."],["Google Cloud SQL, a cloud-based relational database service, offers two connection methods: `Jdbc.getCloudSqlConnection(url)` (recommended) and `Jdbc.getConnection(url)`."],["Non-Cloud SQL databases require authorizing specific IP address ranges for Apps Script access and using `Jdbc.getConnection(url)` for connection."],["Code samples demonstrate creating databases, users, tables, writing and reading data in batches, emphasizing the importance of parameterized statements for security."],["While JDBC connections auto-close after script execution, manual closure using respective `close()` methods is recommended for better resource management."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4