【发布时间】:2015-03-12 12:49:54
【问题描述】:
我正在尝试连接到谷歌云端点内的云 sql,并使用轻量级 jdbc 包装器 sql2o 作为数据访问方法。
@Api(name = "questionapi", version = "v1", description = "question api")
public class QuestionService {
private static Sql2o sql2o = new Sql2o(
"jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxxxx", "root",
"xxxxxxx");
@ApiMethod(name = "get", httpMethod = HttpMethod.GET)
public List<Question> get() {
String q = "select * from questions";
try (Connection conn = sql2o.open()) {
return conn.createQuery(q).executeAndFetch(Question.class);
}
}
应用程序运行后,我可以访问localhost:8888/_ah/api/explorer 试用该api。但是,有一个错误说:
org.sql2o.Sql2oException: Could not acquire a connection from DataSource - No suitable driver found for jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxxxx
我该如何解决这个问题?
编辑:
更改为 maven 项目后,我收到了这个新的错误消息:
503 Service Unavailable
- Show headers -
{
"error": {
"message": "java.lang.NoClassDefFoundError: Could not initialize class com.mysql.jdbc.ConnectionImpl",
"code": 503,
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "java.lang.NoClassDefFoundError: Could not initialize class com.mysql.jdbc.ConnectionImpl"
}
]
}
}
编辑
又是新的一天,我还是卡在这里。
我所做的是使用 maven 下载 endpoints-skeleton-archetype 项目,它是一个可供使用的新的空 Cloud Endpoints 后端 API 项目,包含所需的文件和目录。
我立即将其部署到应用引擎,并尝试返回一个有意义的值。成功了,将返回一个简单的“帮助世界”字符串。
接下来,我尝试使用 jdbc 连接到云 sql。为了做到这一点,我按照教程here
将<use-google-connector-j>true</use-google-connector-j> 添加到 appengine-web.xml
我尝试不同的连接字符串组合
Class.forName("com.mysql.jdbc.GoogleDriver");
String url = "jdbc:google:mysql://xxxxxxxxxxxx:xxxxx?user=root";
conn = DriverManager.getConnection(url);
ResultSet rs = conn.createStatement().executeQuery("SELECT 1 + 1");
在所有这些之后,我仍然收到此错误消息。
503 Service Unavailable
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "java.lang.NullPointerException"
}
],
"code": 503,
"message": "java.lang.NullPointerException"
}
}
【问题讨论】:
-
也有这个问题但无法解决...
标签: google-app-engine google-cloud-endpoints google-cloud-sql