我搜索了许多主题,但是它们都无法帮助我。这是我的情况:
- App Engine(灵活)中的应用
- 第二代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中的使用google-connector-j
有人有线索吗?我已经挣扎了将近两天...
谢谢。
我同意,如果您在本地连接到MySQL,则无需启用连接器。您可以查看此样本。