从Eclipse连接到Google Cloud SQL不使用App Engine [英] Connecting to Google Cloud SQL from Eclipse Not Using App Engine

查看:150
本文介绍了从Eclipse连接到Google Cloud SQL不使用App Engine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正尝试使用数据库开发透视图从Eclipse连接Google Cloud SQL。为此,我试图添加一个新的数据库连接,我可以成功地为我的机器上运行的本地MySQL实例做好准备。



这是我们目前对本地实例运行我们的JUnit测试。但是,我们正在转向Hibernate,并希望确保我们的所有配置文件都可以与Cloud SQL一起使用。作为我一直在使用的一般指南:



https://developers.google.com/appengine/articles/using_hibernate



我们略有差异,因为我们使用hibernate.cfg .xml而不是persistence.xml,但我认为这实际上不会影响当前连接数据库的问题。从另一个答案以及一些Google文档中,我知道我不能使用com.google.appengine.api.rdbms.AppEngineDriver,因为它需要从AppEngine实例运行。相反,我试图按照这里的指示:



https://developers.google.com/cloud-sql/docs/external



并使用com.mysql.jdbc。驱动程序。

我已经为我的Cloud SQL实例分配了一个IP地址,并将我当前的IP地址添加到了白名单,如下所述:



https://developers.google.com/ cloud-sql / docs / access-control#appaccess



我的驱动程序是我一直使用本地实例成功使用的Connector / J驱动程序,我使用的网址是:



jdbc:google:rdbms:// my-app:my-cloud-sql-instance / myDatabase



我得到的:

https://developers.google.com/appengine/ar ticles / using_hibernate



在添加连接并设置信息后,我单击测试连接,该连接在我的本地实例上成功运行。但是,这会引发以下错误:

  java.lang.Exception:连接失败,出现未指定的错误。 
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:110)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:73)
at org.eclipse.datatools.enablement.internal.mysql.connection.JDBCMySQLConnectionFactory.createConnection(JDBCMySQLConnectionFactory.java: 28)
at org.eclipse.datatools.connection.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:
at org.eclipse.datatools.connection.ui.PingJob.run(PingJob.java:
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

显然这不是很有用。



我尝试了一下网址,尝试了很多用户(无其中需要密码,所以我将密码字段留空)以及针对不同版本的MySQL的不同版本的驱动程序。没有任何工作。



这样做可能会有更深层次的问题,比如我将如何轻松地在hibernate.cfg的测试和部署版本之间切换.xml,我没有很好的答案。我只是计划将它们手动编辑回AppEngineDriver,这意味着即使JUnit测试通过,我也可能会遇到进一步的配置问题。尽管如此,我认为建立一个允许JUnit测试的Cloud SQL连接将是朝着正确方向迈出的一步。我会很感激任何输入! /< database-name> 从外部网络连接。您使用的连接字符串是从Google App Engine进行连接。


We are trying to connect to Google Cloud SQL from Eclipse using the Database Development perspective. To do so I'm trying to add a new Database Connection, which I was able to do successfully for a local MySQL instance running on my machine.

The motivation for doing this is that we currently run our JUnit tests against the local instance. However, we are switching to Hibernate and want to make sure that all of our configuration files work with Cloud SQL. As a general guide I've been using:

https://developers.google.com/appengine/articles/using_hibernate

We're diverging slightly in that we're using hibernate.cfg.xml instead of persistence.xml, but I don't think this will actually have a bearing on the current issue of simply connecting to the database. From another answer as well as some Google documentation I'm aware that I can't use the com.google.appengine.api.rdbms.AppEngineDriver, because that needs to be run from an AppEngine instance. Instead I'm trying to follow the directions here:

https://developers.google.com/cloud-sql/docs/external

and am using com.mysql.jdbc.Driver.

I have assigned my Cloud SQL instance an ip address and have added my current ip address to the whitelist, as described here:

https://developers.google.com/cloud-sql/docs/access-control#appaccess

My driver is the Connector/J driver I've been using successfully with the local instance, and the url I'm using is:

jdbc:google:rdbms://my-app:my-cloud-sql-instance/myDatabase

which I got based on:

https://developers.google.com/appengine/articles/using_hibernate

After adding the connection and setting the information I click Test Connection, which worked successfully on my local instance. However, this throws the following error:

java.lang.Exception: Connection failed with unspecified error.
    at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:110)
    at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
    at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:73)
    at org.eclipse.datatools.enablement.internal.mysql.connection.JDBCMySQLConnectionFactory.createConnection(JDBCMySQLConnectionFactory.java:28)
    at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
    at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
    at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
    at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Obviously this isn't very helpful.

I've tried fiddling with the url, tried a number of users (none of which require passwords, so I'm leaving the password fields blank), and different versions of the driver for different versions of MySQL. Nothing has worked.

There are perhaps more deep-seated issues with doing it this way, such as how I will easily switch between test and deployment versions of my hibernate.cfg.xml, and I don't have good answers. I was just planning on editing them by hand back to the AppEngineDriver, which means I might run into further configuration issues at that point even if the JUnit tests are passing. Nevertheless, I think getting a connection set up to Cloud SQL that will allow JUnit testing will be a step in the right direction. I'd appreciate any input!

解决方案

You should use jdbc:mysql://<cloudsql-instance-ip>:3306/<database-name> to connect from an external network. The connection string you are using is to connect from Google App Engine.

这篇关于从Eclipse连接到Google Cloud SQL不使用App Engine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆