0

Is there any way to connect to a SQL Server from an Android application and execute/query SQL statements using Web Service?

Thanks.

1 Answers1

0

You will simply have to access the server via a web connection. I would strongly suggest you write server-side scripts for sql statements. Then you can access the information those serverside scripts provide with a HttpClient. Sample code below.

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(new URI("www.example.com"));
HttpResponse response = client.execute(request);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

Make sure you do all networking in a Async Task.

Also you will need modify your manifest file for Internet permission

<uses-permission android:name="android.permission.INTERNET" />
Ancantus
  • 688
  • 6
  • 18
  • Thanks.. That works Fine.. Now I need the code to update data back to web service.. Suppose its two string values.. How can I do that? –  May 17 '12 at 04:04
  • You mean send data back to the web server? You will have to program some server-side script to accept inputs. Be careful because anyone could post data to your server-side script if they are clever. – Ancantus May 17 '12 at 12:17