连接时出现Google Cloud Sql错误

时间:2012-05-29 10:27:51

标签: google-app-engine google-cloud-sql

我用谷歌应用程序构建云应用程序。虽然与云数据库实例建立连接但是收到错误。我还在Tomcat7.0服务器库中下载并配置了appengine-api-1.0-sdk-1.6.5,我也安装了rdbms包,但仍然是错误相同。代码如下:

<%@ page import="com.google.appengine.api.rdbms.*, java.io.*,java.sql.*"%>
<%
Connection c = null;
DriverManager.registerDriver(new AppEngineDriver());
 c = DriverManager.getConnection("jdbc:google:rdbms://ctsteaching:ctsdatabase/ctsdb");
 String fname = request.getParameter("fname");
  String content = request.getParameter("content");
  if (fname == "" || content == "") {
    out.println("<html><head></head><body>You are missing either a message or a name!       Try again! Redirecting in 3 seconds...</body></html>");
  } else {
  String statement ="INSERT INTO entries (guestName, content) VALUES(?,?)";
  PreparedStatement stmt = c.prepareStatement(statement);
  stmt.setString(1,fname);
  stmt.setString(2,content);
  int success = 2;
  success = stmt.executeUpdate();
  if(success == 1) {
    out.println("<html><head></head><body>Success! Redirecting in 3 seconds...</body>    </html>");
  } else if (success == 0) 
  {
    out.println("<html><head></head><body>Failure! Please try again! Redirecting in 3 seconds...</body></html>");
  }
 }
 %>    

错误如下所示

com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'rdbms' or call 'OpenConnection()' was not found.
com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:98)
com.google.appengine.api.rdbms.RdbmsApiProxyClient$ApiProxyBlockingInterface.makeSyncCall(RdbmsApiProxyClient.java:95)
com.google.appengine.api.rdbms.RdbmsApiProxyClient$ApiProxyBlockingInterface.openConnection(RdbmsApiProxyClient.java:73)
com.google.cloud.sql.jdbc.internal.SqlProtoClient.openConnection(SqlProtoClient.java:58)
com.google.cloud.sql.jdbc.Driver.connect(Driver.java:66)
com.google.cloud.sql.jdbc.Driver.connect(Driver.java:26)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.abcd.test_jsp._jspService(test_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

1 个答案:

答案 0 :(得分:0)

看起来你使用的是错误的jar文件。在本地开发时需要设置一些额外的jvm_flags。 https://developers.google.com/cloud-sql/docs/developers_guide_java#with_eclipse