作者plokijuh (疯人院院长)
看板java
标题Re: [问题] Android 连接到远端资料库(mysql) 使用 …
时间Mon Apr 20 23:26:14 2009
※ 引述《rnbjacky (浪漫A大调)》之铭言:
: 我试着把java的改成android的原始码 如下:
: package com.android.hello;
: import android.app.Activity;
: import android.os.Bundle;
: import android.widget.TextView;
: import java.sql.*;
: public class HelloAndroid extends Activity {
: /** Called when the activity is first created. */
: @Override
: public void onCreate(Bundle savedInstanceState) {
: super.onCreate(savedInstanceState);
: try{
: Class.forName("com.mysql.jdbc.Driver");
: Connection conn =
: DriverManager.getConnection("jdbc:mysql://localhost:3306/android?user=root&password=1234&autoReconnect=true");
: TextView printSuc = new TextView(this);
: printSuc.setText("Connection Successful!");
: setContentView(printSuc);
: }
: catch(SQLException sqle){
: TextView printExc = new TextView(this);
: printExc.setText("SQLException");
: setContentView(printExc);
: }
: catch(ClassNotFoundException sqle){
: TextView printExc = new TextView(this);
: printExc.setText("ClassNotFoundException");
: setContentView(printExc);
: }
: }
: }
: 程式大概就是
: 用helloworld的改
: 然後同java的方式
: 连到localhost的mysql
: 连不到就会显示例外的讯息
: 结果是没办法开启
:  ̄ ̄ ̄ ̄ ̄
: 是Android的内部错误 显示class不能被修改之类的
: 问题一:
: 是Android本身不支援 或是 Android本身其他的问题吗??还是我的程式码有问题
基本上 android 的 localhost 是指手机 or 虚拟器
不是 pc 端,如果要连改成 ip 才会连的到
: 问题二:
: google比赛得奖的作品http://www.cab4me.com/(呼叫计程车)
: 这类的程式应该也是有用到资料库吧?那他们的实作方法是如何的??
: 问题三:
: 要建立资料库来让多个手机(client)存取
: 怎麽样才是最好的方式用来存取远端资料库的资料??
http get or post
: 另外我也google了一下
: 得到了一些回答:
: 提到了三个重点
: (1)用http的方式去抓取资料
: 而不直接联结到资料库的原因就是安全 , 效率 还有driver要配在package里很不方便之
: 类的
肥,手机上没多少空间 mysql driver 就 682k 了
: (2)可以使用REST SOAP的方式
: 这个部分我比较不清楚
http get or post
: 同(1)的意思吗??就是实作的方式是用REST SOAP
: (3)使用Google Data API然後用手机抓取资料
: 这个是我比较有兴趣的方式
: 於是我找了这个:
: http://code.google.com/intl/zh-TW/apis/gdata/
: 其中的这个=>Google Base Data API 可能是我需要的东西
: 但是我对这个API的使用方式 跟架构 都还不了解
: ======================================================
: 目前我的想法是:
: 使用Android api中 http的部分(client)
: 对Google Base Data 存放的资料 进行operation(GET POST ....) (server 的
: interface)
: 回传给Android(client)
: 其中最大的问题在於Google Base Data api
: (1)这个方法可行吗??
: (2)如果可行,请问有什麽建议关於使用Google Base Data api 的方式来实作 远端资料存
: 取
: 或是有什麽成功实例可以参考的??
: 如果对 Android很了解的大大请帮忙解答一下 非常的感激!!
: 这个问题已经困扰好久了ㄒ口ㄒ!!!!!
其实不用直接连资料库
透过 http 将会是最好的选择
用 get or post 透过 http 拿远端资料
--
I Love Android!!
http://wiki.cheyingwu.tw/Android
瘾科科 Android 讨论区
http://android.cool3c.com
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.62.138.17