已部署的应用程序不适用于Google Cloud SQL

时间:2015-06-07 15:11:36

标签: java database google-app-engine gwt jdbc

以下Java代码可以正常使用我的本地数据库,但是当我尝试使用Google数据库时,我会得到以下错误(同样在部署时):

java.lang.ClassNotFoundException: com.mysql.jdbc.GoogleDriver

我已将连接器写入Appennine-web.xml:

<use-google-connector-j>true</use-google-connector-j>

我的Java代码如下所示(第一类,我获得连接):

package edu.example.server.db;

import java.sql.Connection;
import java.sql.DriverManager;




public class DbConnection {



private static Connection con = null;



private static String googleUrl = "jdbc:google:mysql://xx:xx/xx?user=root&password=xx";
//private static String localUrl = "jdbc:mysql://127.0.0.1:3306/xx?user=root&password=xx";


  public static Connection connection() {

    if (con == null) {
        String url = null;
        try {


                Class.forName("com.mysql.jdbc.GoogleDriver");



            con = DriverManager.getConnection(url);
        } catch (Exception e) {
            con = null;
            e.printStackTrace();
        }
    }


    return con;
}

}

第二堂课(我试图得到的东西):

package edu.example.server.db;

import java.sql.*;




public class BauteilMapper {


private static BauteilMapper bauteilMapper = null;


protected BauteilMapper() {
}


public static BauteilMapper bauteilMapper() {
if (bauteilMapper == null) 
  bauteilMapper = new BauteilMapper();


return bauteilMapper;
 }


public String findByKey(int id) {

Connection con = DbConnection.connection();

try {


Statement stmt = con.createStatement();



ResultSet rs = stmt.executeQuery("SELECT idbauteil, name FROM bauteil "
+ "WHERE idbauteil=" + id);


if (rs.next()) {



String name = (rs.getNString("name"));


return name;
}

}
catch (SQLException e2) {
e2.printStackTrace();
return null;
}
return null;
}


}

我在顶部提到的错误报告中找不到任何错误。

谢谢!

0 个答案:

没有答案