Google Cloud Endpoint에 클라우드 SQL에 연결하고 데이터 액세스 방법으로 가벼운 jdbc 래퍼 sql2o
을 사용하려고합니다. Google Cloud Endpoint에서 Sql2o를 사용하여 Cloud SQL에 연결
@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);
}
}
앱을 실행 한 후, 나는 API를 시도
localhost:8888/_ah/api/explorer
를 방문 할 수 있습니다. 그러나 오류가 있습니다 :
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"
}
]
}
}
편집
그것은 새로운 날을, I 아직도 여기 붙어있어. 내가 무슨 짓을
는 필요한 파일 및 디렉토리에 사용할 준비가 비어있는 새 클라우드 엔드 포인트 백엔드 API 프로젝트입니다, 나는 엔드 포인트 골격 원형을 프로젝트를 다운로드 받는다는을 사용합니다.즉시 앱 엔진에 배포하고 의미있는 값을 반환하려고합니다. 효과가 있었고, 단순한 'hellp world'문자열이 반환되었습니다.
다음으로 jdbc를 사용하여 cloud sql에 연결하려고했습니다. 그렇게하기 위해, 나는 에서 appengine-web.xml을
에 <use-google-connector-j>true</use-google-connector-j>
을 추가 튜토리얼 here 을 따라 나는 모든 후 연결 문자열
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"
}
}
는 또한이 문제가 있지만 해결되지 수 ... – Micro