公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

本文介绍了Cloud SQL Postgres找不到适用于JDBC的驱动程序:postgres://google/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提前谢谢!

我是GCP新手,正在尝试使用Cloud SQL Postgres。
我有一个已创建的数据库,并且希望使用Java或Scala在其中创建/更新/删除表。

我正在尝试使用‘com.google.cloud.sql’包中的postgres-Socket-Factory。
但在创建连接时,我收到一个错误,

"java.sql.SQLException: No suitable driver found for jdbc:postgres://google/"

以下是我的代码

def getConnection(url:String) : Connection = {
  Class.forName("org.postgresql.Driver")
  import java.sql.DriverManager
  DriverManager.getConnection(url)
}

Java/Scala客户端通过什么方式从Cloud SQL访问数据库?

按照备注中的说明进行操作并更改URL后是的,该操作有效但失败

    Caused by: java.lang.RuntimeException: Unable to obtain credentials to communicate with the Cloud SQL API
    at com.google.cloud.sql.core.SslSocketFactory$ApplicationDefaultCredentialFactory.create(SslSocketFactory.java:600)
    at com.google.cloud.sql.core.SslSocketFactory.getInstance(SslSocketFactory.java:147)
    at com.google.cloud.sql.postgres.SocketFactory.createSocket(SocketFactory.java:91)
    at org.postgresql.core.PGStream.<init>(PGStream.java:62)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
    at org.postgresql.Driver.makeConnection(Driver.java:454)
    at org.postgresql.Driver.connect(Driver.java:256)
    ... 6 more
Caused by: java.io.IOException: The Application Default Credentials are not available. They are available if running on Google App Engine, Google Compute Engine, or Google Cloud Shell. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:98)
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213)
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:191)
    at com.google.cloud.sql.core.SslSocketFactory$ApplicationDefaultCredentialFactory.create(SslSocketFactory.java:598)
    ... 15 more

如何解决此故障?

问候,

推荐答案

gcp上的大多数库使用Application Default Credentials(Adc)策略来处理凭据。这个项目的README提到了这个库。Cloud SQL JDBC套接字工厂使用这些凭据来根据数据库对连接进行身份验证。

最快捷的方法是使用gcloud auth application-default login,它会将您的个人凭据设置为默认凭据。但是,最安全、最安全的方法是为应用程序创建Service Account,授予它”Cloud SQL Client”IAM角色,并使用GOOGLE_APPLICATION_CREDENTIALS环境变量将服务帐户密钥的位置传递给库。

这篇关于Cloud SQL Postgres找不到适用于JDBC的驱动程序:postgres://google/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,

分享到:
标签:Cloud Postgres SQL 找不到 适用于 驱动程序
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定