-1

I'm developing a native android app and would like to execute stored procedures which are already being used for the web application.

I have used the following links to connect my android app to the SQL Database, which I was able to do successfully.

http://seotoolzz.com/android/android-login-app-with-mssql-server.php

However, to execute the stored procedures, I thought of doing it by having web services in the middle layer (as explained in the below link) and that hasnt worked.

how to get data from sql server using web service in android

Kindly let me know how can I execute the stored procedures.

I would appreciate any help.

Thanks in advance

Community
  • 1
  • 1

2 Answers2

0

You can directly access an MS SQL database through the network using JDBC. Here is some example code of how to construct a URL to access the database:

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    String ConnectionURL = "jdbc:jtds:sqlserver://" + server + "/" + database + ";user=" + user+ ";password=" + password + ";";
    try {
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        Connection con = DriverManager.getConnection(ConnectionURL);
    }
    catch (SQLException se) {
        Log.e("Error:", se.getMessage());
        return false;
    }
Jay
  • 614
  • 5
  • 22
0

If you would like to execute stored procedure and have already connected to the database successfully then run the following:

USE dbname;
GO
EXEC dbo.spname @param1 = value;

saadasharif
  • 80
  • 1
  • 14