【问题标题】:Execute SQL Stored Procedures for the Native Android App为原生 Android 应用程序执行 SQL 存储过程
【发布时间】:2017-02-15 13:22:26
【问题描述】:

我正在开发一个原生 android 应用程序,并希望执行已用于 Web 应用程序的存储过程。

我已使用以下链接将我的 android 应用程序连接到 SQL 数据库,我能够成功地做到这一点。

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

但是,为了执行存储过程,我想通过在中间层使用 Web 服务(如下面的链接中所述)来实现,但没有奏效。

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

请告诉我如何执行存储过程。

我将不胜感激。

提前致谢

【问题讨论】:

  • 你的问题是什么?

标签: android sql-server database android-studio stored-procedures


【解决方案1】:

您可以使用 JDBC 通过网络直接访问 MS SQL 数据库。下面是一些如何构造 URL 来访问数据库的示例代码:

    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;
    }

【讨论】:

    【解决方案2】:

    如果您想执行存储过程并且已经成功连接到数据库,请运行以下命令:

    使用 数据库名称;

    执行 dbo.spname @param1 = ;

    【讨论】:

      猜你喜欢
      • 2010-09-20
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 2018-11-25
      • 2014-03-29
      • 1970-01-01
      相关资源
      最近更新 更多