SQLException Parameter No. 7 not set

so I try to use our login procedure, the problem is that it has three different ways of transferring information back: parameter out, return valueand result, and I'm not sure how to work with this how I get

java.sql.SQLException: parameter number 7 not set

What is my 7th parameter and how exactly should I declare it? make this functional

protected String doInBackground(String...params) {
    if (userid.trim().equals("") || password.trim().equals("")) z = getString(R.string.wrong_user);
    else {
        try {
            Connection con = connectionClass.CONN();
            if (con == null) {
                z = getString(R.string.connection_error);
            } else {
               String query = "{?=call [system].[usp_validateUserLogin](?,?,?,?,?)}";
                    CallableStatement cs = con.prepareCall(query);
                    cs.registerOutParameter(1,Types.INTEGER);
                    cs.setString(2, userid);
                    cs.setString(3, password);
                    cs.setInt(4, 72);
                    cs.setNull(5, Types.BIT);
                    cs.registerOutParameter(6, Types.VARCHAR);
                    boolean firstResultIsResultSet = cs.execute();
                    if (firstResultIsResultSet) {
                        ResultSet rs = cs.getResultSet();
                        // process result set
                    }
                }
                //if (rs.next()) {
                 //   z = getString(R.string.login_succes);
                 //   isSuccess = true;
               // } else {
               //     z = getString(R.string.Invalid_Credentials);
               //     isSuccess = false;
               // }
            }
        } catch (Exception ex) {
            isSuccess = false;
            z = getString(R.string.Exceptions);
        }
    }
    return z;
}

i has SP like next

ALTER PROCEDURE [system].[usp_validateUserLogin]
    @p_Login                NVARCHAR ( 50 ),
    @p_Password             NVARCHAR ( 32 ),
    @p_CompanyID            INT,
    @p_OutDetails           BIT = 1,
    @p_AuthenticationTicket VARCHAR(200) OUTPUT
AS
  BEGIN
      SET NOCOUNT ON;

      DECLARE @errNo    INT,
              @recCount INT,
              @res      INT

      SELECT u.*
      INTO   #TMPLOGIN
      FROM   SYSTEM.[user] AS u WITH ( NOLOCK )
      WHERE  ( u.login = @p_Login )
             AND ( u.company_id = @p_CompanyID )
             AND ( PWDCOMPARE (@p_Password, u.passwd) = 1 )
             AND ( u.status = 0 ) --Active
      SELECT @errNo = @@ERROR,
             @recCount = @@ROWCOUNT

      IF ( @errNo <> 0 )
        BEGIN
            RETURN 1010
        END

      IF ( @recCount = 1 )
        BEGIN
            DECLARE @userID INT

            SELECT @userID = id
            FROM   #TMPLOGIN

            EXEC @res = SYSTEM.USP_RENEWAUTHENTICATIONTICKET
              @p_DoerTicket = '',
              @p_AuthenticationTicket = @p_AuthenticationTicket OUTPUT,
              @p_UserID = @userID,
              @p_CompanyID = @p_CompanyID

            IF ( @res <> 0 )
              RETURN @res
        END

      --SET @p_AuthenticationTicket = 'TESTAUTHENTICATIONTICKET0123456789'
      IF ( @p_OutDetails = 1 )
        BEGIN
            SELECT *
            FROM   #TMPLOGIN
        END

      RETURN 0
  END  

enter image description here

what i tried so far

  • String query = "{call [system].[usp_validateUserLogin](?,?,?,?,?)}";

gaved me

The executeQuery method should return a result.

  1. cs.setNull(7, Types.NULL);

then i get

java.sql.SQLException: procedure or function usp_validateUserLogin contains too many arguments.

  1. cs.setInt(5, 1); all the same

  2. ResultSet rs = cs.executeQuery();

instead

boolean firstResultIsResultSet = cs.execute();
+4
1

, cs.setNull(5, Types.BIT) , ( 1 @p_OutDetails). cs.setBoolean(5, true) {? = [].usp_validateUserLogin}

, , . , ? , , ?

+1

Source: https://habr.com/ru/post/1660955/


All Articles