如何访问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());
        }
}