从android中的远程服务器获取数据 [英] get data from remote server in android

查看:516
本文介绍了从android中的远程服务器获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用oracle db和weblogic作为Web服务器。
从我的Android应用程序,我能够将参数发送到我的远程服务器..
我的问题是如何获取由我的服务器生成的结果设置从我的服务器到我的机器人应用程序???

I am using oracle db and weblogic as web server. From my android app i am able to send parameters to my remote server.. My PROBLEM is HOW TO GET THE RESULT SET GENERATED BY MY QUERY FROM MY SERVER TO MY ANDROID APP???

如果有人向我提供了一些这样做的例子,我将非常感激...

I would be very grateful if someone sites me some examples of doing it...

String result = "";
//the year data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year","1980"));

//http post
try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://example.com/getAllPeopleBornAfter.php");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
 }






下面给出的代码是我的jsp页面......


The code given below is my jsp page...

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"  
pageEncoding="ISO-8859-1"%> 
<%@page import="java.util.*,java.sql.*"%>

<%!
 Connection con;
 PreparedStatement ps;
 String uname,pass;
 ResultSet rs;
%>

<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
 con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","pro","pro");

ps=con.prepareStatement("select * from login_stud");

rs=ps.executeQuery();


}
catch(Exception e)
{
e.printStackTrace();
}
%>

我希望我的Android应用程序检索结果集'rs'....并显示在移动屏幕...怎么做。???如果你想要我的应用程序附近的详细信息你可以问我@dldnh

I want my android app to retrieve the result set 'rs'....and display it on the mobile screen...how to do that.???. if you want details abut my app u can ask me @dldnh

推荐答案

你能做的最好的事情是用一个实现JSON RESTFUL Web服务。

The best thing you can do is to implement JSON with a RESTFUL Web Service.

更多信息:


  1. JSON.ORG

如何创建JSON响应

Android包含JSON类,如JSONArray,JSONObject,可用于解释Web Service将返回的响应。有关详细信息,请参阅此处

Android includes JSON classes such as JSONArray, JSONObject that can be used to interpret the response the Web Service will return. See more at here.

你不会出错。 JSON很快,如果您实施RESTFUL身份验证,有很多方法可以保护通信。

You can't go wrong. JSON is fast, there are ways to secure the communication if you implement RESTFUL Authentication.

最重要的是,您的Web服务将与iOS应用程序和任何其他具有JSON的平台兼容支持。

Best of all your Web Service will be compatible with iOS Apps and any other platform with JSON support.

祝你好运!

这篇关于从android中的远程服务器获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆