[問題] Android 連接到遠端資料庫(mysql) 使用jdbc
我試著把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本身其他的問題嗎??還是我的程式碼有問題
問題二:
google比賽得獎的作品http://www.cab4me.com/(呼叫計程車)
這類的程式應該也是有用到資料庫吧?那他們的實作方法是如何的??
問題三:
要建立資料庫來讓多個手機(client)存取
怎麼樣才是最好的方式用來存取遠端資料庫的資料??
另外我也google了一下
得到了一些回答:
提到了三個重點
(1)用http的方式去抓取資料
而不直接聯結到資料庫的原因就是安全 , 效率 還有driver要配在package裡很不方便之
類的
(2)可以使用REST SOAP的方式
這個部分我比較不清楚
同(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很了解的大大請幫忙解答一下 非常的感激!!
這個問題已經困擾好久了ㄒ口ㄒ!!!!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.227.128.93