作者rnbjacky (浪漫A大调)
看板java
标题[问题] Android 连接到远端资料库(mysql) 使用jdbc
时间Sun Apr 19 00:36:17 2009
我试着把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