最好的方法使用的是Android应用程序来访问数据库服务器的是、最好的、应用程序、服务器

2023-09-05 06:28:30 作者:九兲ˋ炎魔

我需要开发能够访问存储在办公室中的服务器上的SQL Server数据库的应用程序。在值班人员的远程桌面到终端服务器,并使用为该数据库被做了桌面应用程序的数据库。桌面应用程序访问与ODBC连接数据库。 我写一个Android应用程序,这将允许访问这个数据库是在桌面应用程序中提供的一小部分,而我想办法给我的应用程序连接到这个数据库中,无论是使用ODBC连接(可能使用达网络),或以其他方式

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.

编辑:对不起,这些之前,我解释完我的问题谁回答,它发布的事故和一些你回答之前,我完成编辑

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

推荐答案

您必须写在服务器端web服务。可以将数据为JSON数据包发送到设备,在设备解析JSON数据包和访问数据。你的电话到Web服务应该是一个HTTP调用,例如

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:?\服务器\方法An Iteraitve \ get_somedata名=事情

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

和服务器应该在数据库中查询此参数并发送您的效应初探为JSON。  解析JSON,让您的详细信息。

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

编辑: 设置内容类型的服务器响应头应用/ JSON的。这是为客户端发送HTTP POST请求到服务器的例子。这里jsonobjSend是JSON我已经向池莉构建发送到服务器的一些细节。前{表:sometable,编号:90}。 jsonobjRecv是将被服务器发送的JSON

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;

}

创建/分析JSON检查json.org

to create/parse a json check json.org