Android應用程序將在數據庫服務器中顯示外部數據庫(Oracle)的數據。它只能與Web服務(RESTful)一起使用,因此我決定在Java/Java EE本身中開發Web服務。 我不想用PHP或其他一些technologies.Pls建議我繼續這一點。如何從Android應用程序訪問Oracle數據庫。
0
A
回答
0
CouchDB現在非常流行,它與Android很好。 Watch this video.
Apache CouchDB是一個面向文檔的數據庫,可以使用JavaScript以MapReduce方式進行查詢和索引。 CouchDB還提供雙向衝突檢測和解決的增量複製。
CouchDB提供了一個RESTful JSON API,它可以從任何允許HTTP請求的環境訪問。有無數的第三方客戶端庫可以使您的編程語言更加輕鬆。
0
public class RestClient {
private ArrayList <NameValuePair> params;
private ArrayList <NameValuePair> headers;
private String url;
private int responseCode;
private String message;
private String response;
public String getResponse() {
return response;
}
public String getErrorMessage() {
return message;
}
public int getResponseCode() {
return responseCode;
}
public RestClient(String url)
{
this.url = url;
params = new ArrayList<NameValuePair>();
headers = new ArrayList<NameValuePair>();
}
public void AddParam(String name, String value)
{
params.add(new BasicNameValuePair(name, value));
}
public void AddHeader(String name, String value)
{
headers.add(new BasicNameValuePair(name, value));
}
public void Execute(RequestMethod method) throws Exception
{
switch(method) {
case GET:
{
//add parameters
String combinedParams = "";
if(!params.isEmpty()){
combinedParams += "?";
for(NameValuePair p : params)
{
String paramString = p.getName() + "=" + URLEncoder.encode(p.getValue(),」UTF-8″);
if(combinedParams.length() > 1)
{
combinedParams += "&" + paramString;
}
else
{
combinedParams += paramString;
}
}
}
HttpGet request = new HttpGet(url + combinedParams);
//add headers
for(NameValuePair h : headers)
{
request.addHeader(h.getName(), h.getValue());
}
executeRequest(request, url);
break;
}
case POST:
{
HttpPost request = new HttpPost(url);
//add headers
for(NameValuePair h : headers)
{
request.addHeader(h.getName(), h.getValue());
}
if(!params.isEmpty()){
request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
}
executeRequest(request, url);
break;
}
}
}
private void executeRequest(HttpUriRequest request, String url)
{
HttpClient client = new DefaultHttpClient();
HttpResponse httpResponse;
try {
httpResponse = client.execute(request);
responseCode = httpResponse.getStatusLine().getStatusCode();
message = httpResponse.getStatusLine().getReasonPhrase();
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
response = convertStreamToString(instream);
// Closing the input stream will trigger connection release
instream.close();
}
} catch (ClientProtocolException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
} catch (IOException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
}
}
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}
1
依賴於Web服務。它只是RESTful XML嗎? JAX-WS? JSON?不管怎樣,它應該像使用HTTP套接字調出並解析響應一樣簡單。
創建Web服務按照下面的鏈接
使用使用了HTTPClient
public static String hitService(String host, int port, String path, String postBody) throws IOException {
HttpHost target = new HttpHost(host, port);
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(path);
HttpEntity results = null;
try {
HttpResponse response=client.execute(target, get);
results = response.getEntity();
return EntityUtils.toString(results);
} catch (Exception e) {
throw new RuntimeException("Web Service Failure");
} finally {
if (results!=null)
try {
results.consumeContent();
} catch (IOException e) {
// empty, Checked exception but don't care
}
}
}
+0
感謝您的回覆。實際上,我在JSP,Servlet和Struts中有知識。現在我想設計一個Web服務,以便從Android應用程序訪問數據庫服務器中的Oracle數據庫。我想知道如何開發Web服務。 – Mukthi
相關問題
- 1. 如何從Perl訪問Oracle數據庫?
- 2. 如何從Jquery Mobile應用程序訪問遠程數據庫?
- 3. Android應用程序如何訪問集中式數據庫
- 4. 從Android應用程序訪問MS SQL數據庫
- 5. 從Android應用程序訪問外部數據庫
- 6. 從.NET應用程序Android數據庫訪問
- 7. 如何從iPhone應用程序訪問Xcode數據庫
- 8. 如何從移動應用程序訪問WordPress數據庫?
- 9. 如何從另一個應用程序訪問django數據庫
- 10. 如何從ASP.NET應用程序訪問數據庫?
- 11. 如何從ASP.Net應用程序遠程連接oracle數據庫
- 12. 如何從PostgreSQL數據庫訪問Oracle數據庫的源
- 13. 如何從Android應用程序中的服務訪問sqlite數據庫
- 14. 如何從Android的庫類訪問應用程序模塊類?
- 15. 如何從數據庫訪問其他Web應用程序的數據
- 16. 從iPhone應用程序遠程訪問SQL數據庫
- 17. 的Android ADB訪問應用程序數據庫,而根
- 18. 從C#訪問Oracle數據庫#
- 19. 從Visual Studio 2008訪問Oracle數據庫
- 20. 如何讓WPF應用程序訪問在線數據庫?
- 21. 如何訪問多個數據庫中軌3.1.0應用程序?
- 22. 如何讓JPA應用程序訪問不同的數據庫?
- 23. 如何從Android應用程序寫入遠程數據庫
- 24. MS訪問Oracle數據庫
- 25. 訪問oracle數據庫
- 26. 從2個應用程序訪問相同的SQLite數據庫
- 27. 從移動應用程序訪問WordPress數據庫
- 28. 無法從Java應用程序訪問mysql數據庫
- 29. 從新應用程序訪問現有數據庫
- 30. 從iOS應用程序訪問數據庫
你看看SOAP? – Kris
我對它進行了搜索。我發現只有RESTful支持Android,但SOAP純粹是基於XML .Android無法獲得XML格式的響應。 – Mukthi