使用eclipse访问GAE开发环境中的本地MySQL实例 [英] Accessing a local MySQL instance in your GAE development environment for java using eclipse

查看:174
本文介绍了使用eclipse访问GAE开发环境中的本地MySQL实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google App Engine环境的新手。我们正在开始一个使用Google Cloud SQL的项目。出于测试目的,我们需要设置本地MySQL实例。
我试过寻找答案,但我找不到任何帮助我。

I am new to Google App Engine environment. We are starting a project where we are using Google Cloud SQL. For testing purpose we need to setup a local MySQL instance. I have tried searching for the answer, but I didn't find any that helped me.

如果我要总结我的问题,我正在尝试访问我在GAE开发环境中使用Eclipse中的JAVA的本地MySQL实例。

If I was to summarize my question, I am trying access a local MySQL instance in my GAE development environment using JAVA in Eclipse.

推荐答案

您必须在App Engine SDK文件夹中添加MySQL连接器。

You have to add the MySQL connector in you App Engine SDK folder.

您可以在那里找到连接器: http://dev.mysql.com/downloads /连接器/ J /
然后,你必须把它放在这个文件夹中: appengine-java-sdk \lib\impl

You can find the connector there: http://dev.mysql.com/downloads/connector/j/. Then, you have to place it in this folder: appengine-java-sdk\lib\impl

然后你必须运行本地版本的MySQL(例如使用EasyPHP)。

Then you have to run a local version of MySQL (for example using EasyPHP).

以下是可用于连接的代码示例你的数据库(单例):

Here is a sample of the code that you could use to connect to your database (singleton) :

public static Connection getInstance() throws Exception {
  if (connection != null && !connection.isClosed()) {
    return connection;
  }
  if (isLocalTesting) {
    //MySQL
    String url = "jdbc:mysql://127.0.0.1:3306/YOUR_DB_NAME";
    connection = DriverManager.getConnection(url, "root", "");
  } else {
    // Google Cloud SQL
    DriverManager.registerDriver(new AppEngineDriver());
    connection = DriverManager.getConnection("jdbc:google:rdbms://" + instanceName + "/NAME_DB");
  }
  return connection;
}

最后:
您必须在您的脑中包含MySQL库构建路径: http://prntscr.com/124jwm

这篇关于使用eclipse访问GAE开发环境中的本地MySQL实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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