Android的Java的连接到在线数据库 [英] Android Java connect to online database

查看:140
本文介绍了Android的Java的连接到在线数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我有我的网站托管与1and1.com数据库。

Okay so i have a database hosted with 1and1.com from my website..

如何从Android的连接数据库和存储信息,并检索应用程序的信息?

How can i from android connect the database and store info and also retrieve info from the app?

推荐答案

我以为你知道的Web服务。 使用.NET,然后使用 KSOAP库编写一个Web服务你会得到响应。 然后根据您的要求格式化响应。 code,以供参考:

I assume that you know about web service. write a web service using .net and Then by using ksoap library you will get response. Then Format that response according to your requirement. code for reference:

private static final String NAMESPACE = "http://tempuri.org/"; 
private static final String URL ="http://localhost/Web_Service.asmx?";// you can use   IP address instead of localhost
private static final String METHOD_NAME = "Function_Name";
private static final String SOAP_ACTION = NAMESPACE+METHOD_NAME;

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
request.addProperty("parm_name",prm_value);// Parameter for Method
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);//call the eb service Method
} catch (Exception e) {
e.printStackTrace();}//Next task is to get Response and format that response
SoapObject obj,obj1,obj2,obj3;
obj= (SoapObject) envelope.getResponse();
obj1=(SoapObject) obj.getProperty("diffgram");
obj2=(SoapObject) obj1.getProperty("NewDataSet");
for(int i=0;i<obj2.getPropertyCount();i++)//the method getPropertyCount() return the number of rows
{
obj3=(SoapObject) obj2.getProperty(i);  
obj3.getProperty(0).toString();//value of column 1
obj3.getProperty(1).toString();//value of column 2
//like that you will get value from each column
}

<一个href="http://$c$c.google.com/p/ksoap2-android/downloads/detail?name=ksoap2-android-assembly-2.4-jar-with-dependencies.jar&can=2&q="相对=nofollow>链接的KSOAP库为Android

您可以从上面的链接下载库。 我HPOE这将解决您的问题。 添加评论,如果您有关于任何问题。

You can Download Library from above link. I hpoe this will solve your problem. Add comment if you have any problem regarding that.

这篇关于Android的Java的连接到在线数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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