Re: [問題] Android 連接到遠端資料庫(mysql) 使用 …

看板java作者 (瘋人院院長)時間16年前 (2009/04/20 23:26), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
※ 引述《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
文章代碼(AID): #19x9GPpJ (java)
文章代碼(AID): #19x9GPpJ (java)