如何访问Microsoft SQL Server数据库的Andr​​oid应用程序 [英] How to Access Microsoft SQL Server Database ‎for Android Application

查看:176
本文介绍了如何访问Microsoft SQL Server数据库的Andr​​oid应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开发当中,应用程序的数据被保存在。我要检索的Microsoft SQL Server数据库中的数据的微软SQL Server数据库的client.In Android应用程序。平时我从MySQL数据库和PHP Web服务器作为检索和使用JSON解析,我没有埋头它。我不要有任何线索,以与Microsoft SQL Server连接Database.I几个一派times.But没有好的suggetion。可以任你的工作就可以了?或有什么想法,请与me.its十分迫切分享..先谢谢了。

I am going to develop an Android application for a client.In which , the data for the application is saved in the Microsoft SQL Server Database .I have to retrieve the data's from Microsoft SQL Server Database. usually I retrieve from mysql database with php as webserver and parsed with json, i am not having hard at it.I dont have any clue to connect with Microsoft SQL Server Database.I googled Several times.But there is no good suggetion .Can any of you worked on it?? or have any ideas please share with me.its very urgent.. Thanks in Advance.

推荐答案

要直接访问它,你可以使用JDBC驱动程序。

To access it directly, you can use a JDBC driver.

http://jtds.sourceforge.net/

在这里下载jar文件:

Download the jar file here:

http://sourceforge.net/projects/jtds/

样code:

public void ConnectToDatabase(){
    try {
         Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
         String username = "XXX";
         String password = "XXX";
         Connection DbConn = DriverManager.getConnection("jdbc:jtds:sqlserver://192.188.1.1:1433/DATABASE;user=" + username + ";password=" + password);

        Log.w("Connection","open");
        Statement stmt = DbConn.createStatement();
        ResultSet reset = stmt.executeQuery(" select * from users ");


        EditText num = (EditText) findViewById(R.id.displaymessage);
        num.setText(reset.getString(1));

        DbConn.close();

        } catch (Exception e)
        {
           Log.w("Error connection","" + e.getMessage());
        }
}

这篇关于如何访问Microsoft SQL Server数据库的Andr​​oid应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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