mysql - ClassNotFoundException : com. mysql.jdbc.GoogleDriver 错误

标签 mysql mysql-workbench

我想知道在 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/

相关文章:

mysql - find_in_set 和 find_in_set 意外结果

mysql - 如何从计数中选择具有最大产值的行

mysql - 如何在 MySQL Workbench 中禁用 SSL 要求?

java - 尝试将我的 java netbeans j 表注册表的数据放入 MySQL 时,我不断出错

php - 将 CSV 导入 MySQL Workbench,其中文本字段包含数据换行符

php - 多类(class)、相互关联的学校时间表作为 MySQL 数据库

php - MYSQL 具有总计的不同值

php - 使用索引改进 MySQL 表

mysql - MySQL DECLARE 中的 SELECT INTO 变量导致语法错误?

php - 我觉得我把我的表现逻辑和我的模型逻辑混合得太多了。一些帮助?