我想知道在 APP ENGINE 中托管我的项目时为什么会抛出此错误,我添加了很多日志记录只是为了分析。当我使用本地的 ip 使用 com.mysql.jdbc.Driver 时,它可以工作。请帮忙!!
String name = "Vinodh";
String url = null;
try {
Class.forName("com.mysql.jdbc.GoogleDriver");
url = "jdbc:google:mysql://xxxxxxx:xxxxxx/vinodh?user=root&password=xxxxxx";
// Statements allow to issue SQL queries to the database
log.info("Initiate Connection");
Connection conn = DriverManager.getConnection(url);
log.info("Got Connection");
Statement statement = conn.createStatement();
// Result set get the result of the SQL query
ResultSet resultSet = statement
.executeQuery("select * from Family");
log.info("Entering While");
while(resultSet.next()){
log.info("Entered While");
String test = resultSet.getString("Name");
System.out.println(test);
name = test+test+test;
}
最佳答案
如本教程所示,在开发过程中,您应该使用普通的 mysql 驱动程序,只有 appengine 使用 Google mysql 驱动程序
if (SystemProperty.environment.value() ==
SystemProperty.Environment.Value.Production) {
// Load the class that provides the new "jdbc:google:mysql://" prefix.
Class.forName("com.mysql.jdbc.GoogleDriver");
url = "jdbc:google:mysql://your-project-id:your-instance-name/guestbook?user=root";
} else {
// Local MySQL instance to use during development.
Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://127.0.0.1:3306/guestbook?user=root";
}
还要仔细检查您是否为您的应用程序启用了 MySQL Connector/J(默认情况下未启用)
https://developers.google.com/appengine/docs/java/cloud-sql/#enable_connector_j
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
...
<use-google-connector-j>true</use-google-connector-j>
</appengine-web-app>
关于mysql - ClassNotFoundException : com. mysql.jdbc.GoogleDriver 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20173043/