简体   繁体   English

如何将数据从android发送到SQL Server 2008?

[英]How to send data from android to SQL Server 2008?

I have created one web site and android applcation and I have used backed as SQL Server 2008. I have used web services to display data from server to android application for that i have used JSON and ksoap library and it is working fine. 我创建了一个网站和android应用程序,并使用了支持的SQL Server2008。我使用了Web服务来显示从服务器到android应用程序的数据,因为我已经使用了JSON和ksoap库,并且运行良好。 I can display data from server to android. 我可以显示从服务器到Android的数据。 But now i want to store data from android application to SQL Server 2008. So anyone please tell me the step or how i can do that. 但是现在我想将数据从android应用程序存储到SQL Server2008。所以任何人都可以告诉我该步骤或我该怎么做。 Please help. 请帮忙。

You can connect to SQL Server database through webservice. 您可以通过Web服务连接到SQL Server数据库。

Here is the sample code to call the webservice. 这是调用Web服务的示例代码。

String url = "your_webservice_URL";

 try 
 {
    HttpPost loginHttpPost   = new HttpPost(url); 
    HttpContext localContext = new BasicHttpContext();          

    MultipartEntity multipartContent = new MultipartEntity();
    multipartContent.addPart("parameter1", new StringBody(value1));
    multipartContent.addPart("parameter2", new StringBody(value2));
    loginHttpPost.setEntity(multipartContent);

    HttpClient objHttpClient = new DefaultHttpClient();
    HttpResponse response = objHttpClient.execute(loginHttpPost,localContext);
 } 
 catch (IOException e) {
     e.printStackTrace();}

Here is the example source code to Connect Android to SQL sever via WCF using JSON 这是Connect Android to SQL sever via WCF using JSON的示例源代码

Example : 范例:

1. Connecting Android to SQL Server 1.将Android连接到SQL Server

2. Get Data using XML 2.使用XML获取数据

3. Get Data using JSON 3.使用JSON获取数据

- Inserting Data into database using WCF Service -使用WCF服务将数据插入数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM