How to access Microsoft SQL Server database ‎for Android application? [closed]

拟墨画扇 提交于 2019-12-23 06:07:12

问题


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.

Usually I retrieve from MySQL database with PHP as webserver and parsed with json, I am not having hard at it. I don't have any clue to connect with Microsoft SQL Server Database.

I googled several times, but there is no good suggestion. Have any of you worked on it? Or if you have any ideas please share with me.


回答1:


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

http://jtds.sourceforge.net/

Download the jar file here:

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

Sample 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());
        }
}


来源:https://stackoverflow.com/questions/21979473/how-to-access-microsoft-sql-server-database-for-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!