gpt4 book ai didi

java - 找不到合适的驱动程序 : jdbc:google:mysql

转载 作者:行者123 更新时间:2023-11-29 01:55:28 24 4
gpt4 key购买 nike

我想弄清楚为什么我的 App Engine(端点)程序无法连接和/或加载 jdbc google mysql 驱动程序。

我已经启用了 <use-google-connector-j> appengine-web.xml 中的标记并将其设置为 TRUE按照说明 here .

appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>...</application>
<version>1</version>
<threadsafe>true</threadsafe>
<use-google-connector-j>true</use-google-connector-j>


<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties" />
</system-properties>
</appengine-web-app>

还有我尝试连接 Google Cloud SQL 的端点方法:

 @ApiMethod(name = "lesson")
public Lesson getLesson(@Named("id") int id) throws SQLException {


// Create new lesson object
Lesson l = new Lesson();

// Create resultSet for database retrieval
ResultSet rs = null;
Connection c = null;
// connect to the database
// Connection c = DatabaseConnect();
String talk = "";
try {
Class.forName("com.google.cloud.sql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.getStackTrace().toString();
l.setLessonObjectives(e.getMessage());
}

String url = "jdbc:google:mysql://" + Constants.PROJECT_NAME + ":" + Constants.SQL_INSTANCE_NAME + "/" + Constants.SQL_DATABASE_NAME + "?user=root";
try {
c = DriverManager.getConnection(url);
talk = talk + "..... And now i'm going to connect";
} catch (SQLException e) {
e.printStackTrace();
l.setLessonDescription(e.getMessage() + " ---- " + e.getErrorCode() + " ----- " + e.getSQLState());
}

// check to make sure there is a connection available
// execute query and save it in a result set.
if(c != null) {
try {

rs = c.createStatement().executeQuery(
"SELECT * FROM se_lesson WHERE id = " + id);

if (rs.first()) {

l.setLessonId(id);
l.setLessonName(rs.getString("lesson_name"));
l.setLessonObjectives(rs.getString("lesson_objectives"));
l.setLessonDescription(rs.getString("lesson_description"));
l.setLessonMinCoins(rs.getInt("lesson_min_coins"));
l.setLessonLevel(rs.getInt("lesson_level_id"));
l.setLessonColour(rs.getString("lesson_color"));

} else {
l.setLessonId(-1);
}

} catch (SQLException e) {
e.printStackTrace();
l.setLessonId(-2);

}
}

l.setLessonObjectives(talk);



logger.info("Calling getLesson method");

return l;
}

当我通过 APIs Explorer 调用端点时返回的错误消息是:

{
"lessonId": 0,
"lessonDescription": "No suitable driver found for jdbc:google:mysql://stark-english:content-instance/stark?user=root ---- 0 ----- 08001",
"lessonObjectives": "I think its loaded",
"lessonMinCoins": 0,
"lessonLevel": 0,
"kind": "stark#resourcesItem",
"etag": "\"2PYCr435swl6FqpdQwvud90MSME/LgtErz4rWHsMTKvNQvVMw3CDWhw\""
}

知道为什么即使我正在调用 Google 连接器并且它没有返回 ClassNotFoundException 也会发生这种情况吗? ?

更新 1:

是的,我在我的 Android Studio 项目中包含了 mysql 连接器。如下图:

Build library

App Engine Module libraries/dependencies

最佳答案

CloudSQL 驱动类名称是:“com.mysql.jdbc.GoogleDriver”。您正在使用:“com.google.cloud.sql.jdbc.Driver”。

请注意,根据您打开连接的位置(本地或服务器上),您将需要在驱动程序之间切换,如 documentation 中所述。 .

要在 mysql 服务器上本地打开连接,您需要使用驱动程序:“com.mysql.jdbc.Driver”并适当修改连接 URL。

关于java - 找不到合适的驱动程序 : jdbc:google:mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30339312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com