我使用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;
}
}
答案 0 :(得分:6)
像Jaochim一样悲伤的问题是jre1.7.0_25 我重新安装到jre1.7.0_21,它的工作原理。 谢谢。
答案 1 :(得分:2)
您应该从以下位置更改连接字符串:
"jdbc:mysql://localhost:3306/onekilometre"
要 “JDBC:谷歌:RDBMS:// INSTANCE_NAME /数据库”
您将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实例,如果您在本地服务器上运行时根据您在转到Project Properties时设置的设置谷歌| App Engine |谷歌可以SQL,然后点击Configure
。请记住选择Use MySQL instance
单选按钮。
每次都不需要更改连接字符串!如果在本地运行,则将使用本地实例。如果您从Google服务器运行,则将使用云实例。
答案 2 :(得分:1)
我遇到了与jre1.7.0_25相同的问题,并通过升级到jre1.7.0_45解决了这个问题。