第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我如何在沒(méi)有應(yīng)用引擎的情況下連接谷歌云實(shí)例

我如何在沒(méi)有應(yīng)用引擎的情況下連接谷歌云實(shí)例

阿晨1998 2021-09-29 16:44:19
我正在嘗試連接到谷歌云實(shí)例,但遇到了一些麻煩。我很感激幫助找到最簡(jiǎn)單的方法。我也是使用數(shù)據(jù)庫(kù)和 Java 的新手。這是我的代碼:package com.google.cloud.sql.mysql;import java.io.IOException;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;/*** A sample app that connects to a Cloud SQL instance and lists all available tables in a database. */public class example{  public static void main(String[] args) throws IOException, SQLException {// TODO: fill this in// The instance connection name can be obtained from the instance overview page in Cloud Console// or by running "gcloud sql instances describe <instance> | grep connectionName".String instanceConnectionName = "eco-codex-216813:asia-southeast1:instance1";// TODO: fill this in// The database from which to list tables.String databaseName = "mysql";String username = "root";// TODO: fill this in// This is the password that was set via the Cloud Console or empty if never set// (not recommended).String password = "1412";//[START doc-example]String jdbcUrl = String.format(    "jdbc:mysql://google/%s?cloudSqlInstance=%s"        + "&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false",    databaseName,    instanceConnectionName);Connection connection = DriverManager.getConnection(jdbcUrl, username, password);try (Statement statement = connection.createStatement()) {  ResultSet resultSet = statement.executeQuery("SHOW TABLES");  while (resultSet.next()) {    System.out.println(resultSet.getString(1));    }   }  }}
查看完整描述

1 回答

?
DIEA

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊

歡迎使用 Stackoverflow 和 Google Cloud!我假設(shè)您的意思是帶有“Google 云實(shí)例”的帶有 MySQL 引擎的 Google Cloud SQL 實(shí)例。您需要打開從運(yùn)行 Java 程序的機(jī)器到 Cloud SQL 實(shí)例的網(wǎng)絡(luò)級(jí)別訪問(wèn)權(quán)限。在 Cloud SQL 中,默認(rèn)行為是阻止外部訪問(wèn)。您可以在云控制臺(tái)中編輯實(shí)例,并在“授權(quán)網(wǎng)絡(luò)”部分添加您的 IP 地址或 IP 范圍以允許連接。

如果您的 Java 機(jī)器和 Cloud SQL 之間沒(méi)有其他防火墻,您應(yīng)該能夠在此更改后進(jìn)行連接。希望能幫助到你!

您可以從此頁(yè)面找到有關(guān) Cloud SQL 連接的更多信息:https : //cloud.google.com/sql/docs/mysql/connect-external-app#appaccessIP。您還可以找到連接到數(shù)據(jù)庫(kù)的其他選項(xiàng),例如使用代理。


查看完整回答
反對(duì) 回復(fù) 2021-09-29
  • 1 回答
  • 0 關(guān)注
  • 151 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)