3

我正在使用 Google App Engine 对本地计算机进行编程并将 MySql 连接到我的项目,当我尝试连接到 mysql 时出现错误。有什么想法吗?谷歌搜索只给出了一件类似的事情: https ://dba.stackexchange.com/questions/45029/mysql-exception-after-upgrading-from-java-6-to-java-7

INFO: Dev App Server is now running
java.sql.SQLException: Unable to initialize driver properties due to java.lang.IllegalAccessException: Class com.google.appengine.tools.development.agent.runtime.Runtime can not access a member of class com.mysql.jdbc.ConnectionPropertiesImpl with modifiers "private"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2819)
at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3490)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:823)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:127)
at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:135)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ru.onekilometre.SQLConnectionProvider.getInstance(SQLConnectionProvider.java:18)
at ru.onekilometre.OnekilometreServlet.doGet(OnekilometreServlet.java:19)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectRequest(DevAppServerServersFilter.java:369)
at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectServerRequest(DevAppServerServersFilter.java:352)
at com.google.appengine.tools.development.DevAppServerServersFilter.doFilter(DevAppServerServersFilter.java:115)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:480)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

连接代码为:

package ru.onekilometre;

import java.sql.DriverManager;

import com.google.cloud.sql.jdbc.Connection;


public class SQLConnectionProvider {
public static Connection connection;
public static Connection getInstance() throws Exception {

      if (connection != null && !connection.isClosed()) {
        return connection;
      }
     // if (true) {
        //MySQL
        String url = "jdbc:mysql://localhost:3306/onekilometre";
        connection = (Connection) DriverManager.getConnection(url, "raiym", "password");
    /*  } else {
        // Google Cloud SQL
        DriverManager.registerDriver(new AppEngineDriver());
        String instanceName = "somename";
        connection = (Connection) DriverManager.getConnection("jdbc:google:rdbms://" + instanceName + "/NAME_DB");
      }*/
      return connection;
    }

}

4

3 回答 3

6

就像 Jaochim 可悲的问题是 jre1.7.0_25 我重新安装到 jre1.7.0_21 并且它可以工作。谢谢。

于 2013-07-21T14:04:45.683 回答
2

您应该从以下位置更改连接字符串:

"jdbc:mysql://localhost:3306/onekilometre"

到“jdbc:google:rdbms://instance_name/database”

您将替换instance_name为您的 Google Cloud SQL 实例名称和database您的数据库名称。请参阅https://developers.google.com/appengine/docs/java/cloud-sql/developers-guide#connect_and_post。例如,在我的应用程序中,我有:

"jdbc:google:rdbms://namibiaonthenet:namibiaonthenet/barcodeapp"

如果您在本地服务器上运行, App Engine会自动替换此字符串以连接到您的本地 MySQL 实例,根据您在转到项目属性 | 时设置的设置。谷歌 | 应用引擎 | Google 可以 SQL,然后单击Configure. 请记住选择Use MySQL instance单选按钮。

无需每次都更改连接字符串!如果您在本地运行,将使用您的本地实例。如果您从 Google 服务器运行,将使用云实例。

于 2013-07-21T20:29:50.053 回答
1

我对 jre1.7.0_25 有同样的问题,并通过升级到 jre1.7.0_45 解决了它。

于 2014-01-02T20:29:01.943 回答