【问题标题】:Trouble connecting to Google Could SQL database (no suitable driver found....)无法连接到 Google Cloud SQL 数据库(找不到合适的驱动程序......)
【发布时间】:2016-12-12 15:27:27
【问题描述】:

我搜索了很多主题,但没有一个可以帮助我。这是我的情况:

  • 应用引擎中的应用(灵活)
  • 第二代MySQL数据库
  • 两者都存在于同一个项目中

POM.xml 中的依赖关系:

  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.4</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.39</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.appengine</groupId>
      <artifactId>appengine-api-1.0-sdk</artifactId>
      <version>1.9.48</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud.sql</groupId>
      <artifactId>mysql-socket-factory</artifactId>
      <version>1.0.2</version>
    </dependency>
  </dependencies>

Java 代码:

    String jdbcUrl = String.format(
            "jdbc:mysql://google/%s?cloudSqlInstance=%s&socketFactory=com.google.cloud.sql.mysql.SocketFactory",
            "MyTable",
            "xxxx:us-central1:xxxx");

    con = DriverManager.getConnection(jdbcUrl, "root", "xxxxxx");
    Statement statement = con.createStatement();
    ResultSet resultSet = statement.executeQuery("SHOW TABLES");
    while (resultSet.next()) {
        ...
    }

当我使用以下方式将应用程序部署到云时出现以下错误:

mvn appengine:update

No suitable driver found for jdbc:mysql://google/MyTable?cloudSqlInstance=xxxx:us-central1:xxxx&socketFactory=com.google.cloud.sql.mysql.SocketFactory

据我了解,我的 appengine-web.xml 中不需要 use-google-connector-j

谁有线索?我已经为此苦苦挣扎了将近两天...

谢谢。

【问题讨论】:

    标签: google-app-engine google-cloud-sql


    【解决方案1】:

    我同意,如果您在本地连接到 mysql,则不需要启用连接器。您可以查看this 示例。

    【讨论】:

      猜你喜欢
      • 2017-07-27
      • 2019-08-17
      • 2017-01-06
      • 1970-01-01
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-01
      相关资源
      最近更新 更多