我正在努力找出为什么我的App Engine(Endpoints)程序无法连接和/或加载jdbc谷歌mysql驱动程序。
我已经在appengine-web.xml中启用了标签,并将其设置为TRUE,如此处所指定。
当我通过APIs Explorer调用端点时返回的错误消息是:
任何想法为什么会发生这种情况,即使我调用了Google连接器,它也没有返回ClassNotFoundException?
更新1:
是的,我已经在我的Android Studio项目中包含了mysql连接器。如下所示:
我已经在appengine-web.xml中启用了标签,并将其设置为TRUE,如此处所指定。
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连接器。如下所示: