Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从android应用程序调用存储过程?_Android_Sql Server 2008_Stored Procedures - Fatal编程技术网

如何从android应用程序调用存储过程?

如何从android应用程序调用存储过程?,android,sql-server-2008,stored-procedures,Android,Sql Server 2008,Stored Procedures,我想从SQLServer调用一个存储过程来操作登录页面 但不断出现这样的错误: import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Sp { public static void main(String[] args) { String

我想从SQLServer调用一个存储过程来操作登录页面 但不断出现这样的错误:

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class Sp
{
    public static void main(String[] args)
    {

         String dbName = "My_database";
         String serverip="192.168.5.10";
         String serverport="1433";

         String url = "jdbc:sqlserver://"+serverip+"\\SQLEXPRESS:"+serverport+";databaseName="+dbName+"";


         try

        {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        }

        catch(ClassNotFoundException ex)
        {
            ex.printStackTrace();
        }

        Connection con=null;
        CallableStatement cstmt=null;
        try
        {

             String databaseUserName = "sa";
             String databasePassword = "a123";

            con= DriverManager.getConnection(url, databaseUserName, databasePassword);


            cstmt=con.prepareCall("{? = call spLoginvalidate(@CO_ID)}");//called the procedure
                                        //how to create procedure had writen in  bellow
            cstmt.executeUpdate();
            System.out.println("done");
        } 

        catch(SQLException ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            try
            {
                if(cstmt!=null) //close the callablestatement
                {
                    cstmt.close();
                    cstmt=null;
                }
            }
            catch(SQLException ex)
            {
                ex.printStackTrace();
            }
            try
            {
                if(cstmt!=null)  //close the connection
                {
                    cstmt.close();
                    cstmt=null;
                }
            }
            catch(SQLException ex)
            {
                ex.printStackTrace();
            }
        }
    }
}
我的错误消息是:

com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 1.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildParamTypeDefinitions(SQLServerPreparedStatement.java:260)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(SQLServerPreparedStatement.java:219)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(SQLServerPreparedStatement.java:612)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:400)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:314)
    at com.first.mainapp.Sp.main(Sp.java:45)
如果要使用存储过程验证登录名而不是

        cstmt=con.prepareCall("{? = call spLoginvalidate(@CO_ID)}");//called the procedure
试一试

您可以在此处获得更多信息:


SQL Server不知道
调用
语句。改用
EXEC

对不起,我必须如何将值编码为?意思是我必须说cs.registerOutParameter(1,Types.VARCHAR);cs.setInt(2,20)//您的@CO_ID值很抱歉,只是有点困惑
        cstmt=con.prepareCall("{EXEC ? = spLoginvalidate(?)}");//called the procedure

        cs.registerOutParameter(1, Types.INT);
        cs.setInt(2, 1000);//your @CO_ID value here