Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to access database on server using Android Application

Tags:

android

sql

I need to develop an application which can access an SQL Server database stored on a server in an office. On call staff remote desktop into a terminal server, and access the database using the desktop application for which the Database was made. The desktop application accesses the database with an ODBC connection. I am writing an android application which will allow a small part of the access to this database that is available in the desktop application, and I am looking for ways to connect my application to this database, whether it is using the ODBC connection (Potentially using .Net), or in some other way.

Edit: Sorry for those who replied before I finished explaining my question, it posted by accident and some of you answered before I finished editing.

like image 699
Dazzmaster1 Avatar asked Dec 15 '11 09:12

Dazzmaster1


People also ask

Can you run access database on Android?

The virtual desktop runs on the Windows platform. Users can work on the Access database on the Android phone or tablet as they would on their Windows machine. Additionally, the Access database can be split into the front-end and back-end.

Can an app access a database?

One option consists of syncing (or migrating) the data to a mobile friendly database such as SQLite. Once the data is in this format, Android apps can interact with it. To access the information, you would need to develop an app that would communicate with the database and allow you to make edits.


1 Answers

you have to write a webservice on the server side. can send the data as Json packets to the device and in device parse the json packets and access the data. your calls to webservice should be a http call eg

http:\server\metnod\get_somedata?name=something

and the server should query the database for this parameter and send you the reponse as Json. parse json and get your details.

Edit: set the content-type as "application/json" in the server response header. This is a example for client to send a http post request to the server. here jsonobjSend is the json i have contructed to send to the server with some details. ex {table:"sometable", id:90 }. jsonobjRecv is the json which will be sent by the server

    HttpPost httpPostRequest = new HttpPost(url);
        StringEntity se;
        se = new StringEntity(jsonObjSend.toString());

        // Set HTTP parameters
        httpPostRequest.setEntity(se);
        httpPostRequest.setHeader("Authorization", usercredential);
        httpPostRequest.setHeader("Accept", "application/json");
        httpPostRequest.setHeader("Content-type", "application/json");
        httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression
        long t = System.currentTimeMillis();
        response = (HttpResponse) httpclient.execute(httpPostRequest);
        Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis()-t) + "ms]");
        //Get hold of the response entity (-> the data):
        HttpEntity entity = response.getEntity();

        if (entity != null) {
            // Read the content stream
            InputStream instream = entity.getContent();
            Header contentEncoding = response.getFirstHeader("Content-Encoding");
            if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                instream = new GZIPInputStream(instream);
            }

            // convert content stream to a String
            String resultString= convertStreamToString(instream);
            Log.v(null, "resultString "+resultString);
            instream.close();


            // Transform the String into a JSONObject
            if(resultString!=null){
                jsonObjRecv = new JSONObject(resultString);

            }

            // Raw DEBUG output of our received JSON object:
            Log.i(TAG,"<jsonobject>\n"+jsonObjRecv.toString()+"\n</jsonobject>");

            return jsonObjRecv;

}

to create/parse a json check json.org

like image 196
AD14 Avatar answered Sep 21 '22 13:09

AD14