如何实现,并使用谷歌云SQL在我的Andr​​oid应用程序(日蚀) [英] How to implement and use google cloud sql in my android app (eclipse)

查看:154
本文介绍了如何实现,并使用谷歌云SQL在我的Andr​​oid应用程序(日蚀)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来像一个愚蠢的问题,它可能看起来像我没有搜索出有一个答案,但。

this would look like a dumb question and it may look like I didn't search out there for an answer but.

现在的问题是,我开发一个Android应用程序,并在某一点上我的新约

The problem is that I am developing an android app and at a certain point I new about

谷歌云SQL

谷歌应用程序引擎

让我看着像20-30教程,并开始实施,但现在我被卡住,找不到任何教程,展示一步步的简单安卓code。

so I watched like 20-30 tutorial and started implementing, but now I'm stuck and can find no tutorial that shows a step by step simple android code.

下面是我做了什么,并在那里我坚持现在:

Here's what I've done and where I'm stuck right now:

- 我的Andr​​oid应用程序是伟大的工作没有一个单一的错误

-my android app is working great no single error

-created一个App Engine项目

-created an app engine project

-turned对谷歌云SQL服务,它的API服务,并支付了

-turned on Google Cloud SQL service and it's API service and paid for that

在云-created实例

-created an instance in the cloud

- 和通过API控制台在我的实例中创建一个表和一个小型的数据库

-and "through the api console" created a table and a small database in my instance

- 生成一个App Engine支持对我的应用程序包

-generated an App Engine backed for my application package

和这里就是我卡住了!我不知道如何使用生成的文件,是如何工作的,我怎么能访问表中的云,通过我的应用程序,找不到教程讲解如何发生的,所有教程在那里只是跳过这一步,如果是最容易的事在世界上。

And here it's where I got stuck !!! I don't know how to use the generated files, how things work, how can I access the table in the cloud through my app, COULD FIND NO TUTORIAL explaining how does that happen, all tutorials out there just skip that step as if it's the easiest thing in the world.

我只是想知道如何做的事情一起工作?哪里权的方法,做什么我必须做的,从表中这是在云中的实例,让我的数据...

I just want to know how does things work together? where to right the methods, what do I have to do to get my data from the table in the instance which is in the cloud...

我会AP preciate甚至没有任何链接:)谢谢你。

I would appreciate even any link :) thank you.

推荐答案

如果你还没有得到这个想通了没有,这是我做的。

If you haven't got this figured out yet, this is what I did.

在开发者控制台注意你的项目数量和你的API密钥。另外,请确保您的云实例可以访问到你的项目的ID。

In the developer console note your project number and your API key. Also make sure your cloud instance allows access to your project ID.

  1. 创建一个应用程序引擎的连接工程。文件>新建>其它>安卓>应用程序引擎连接的Andr​​oid项目。
  2. 输入您的项目数量和API密钥。
  3. 一旦创建了项目,然后右键单击生成的应用程序引擎项目>谷歌>应用程序引擎设置,并从开发者在应用程序ID字段控制台输入项目编号。
  4. 右键单击生成应用程序引擎项目>谷歌>生成云端点客户端库
  5. 右键单击生成应用程序引擎项目>谷歌>部署到App Engine的

现在,你可以叫你从Android应用程序,云SQL数据库。但你必须这样做,作为一个AsyncTask的。对于我,直到我做了这一点,没有工作。创建的AsyncTask类,并在doInBackground连接到您的数据库。我做我的是这样的:

Now you can call you cloud SQL database from the android app. but you have to do it as an AsyncTask. It did not work for me until I did this. Create an AsyncTask class and in the doInBackground connect to your DB. I did mine like this:

  public class Connect extends AsyncTask<Context, Integer, Long> {

    protected Long doInBackground(Context... contexts) {

        Connection connection;
        String query = "Some query";
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://<your cloud IP address>/<database schema you want to connect to>", "<user>", "<password>");

            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(query);

如果您已经创建了一个Android项目,只需右键单击该项目>谷歌>生成App Engine的后端,并从第2步我希望这有助于启动。

If you already created an android project, just right click that project > Google > Generate App Engine Backend and start from step 2. I hope this helps.

这篇关于如何实现,并使用谷歌云SQL在我的Andr​​oid应用程序(日蚀)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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