so i am trying to use our login procedure the problem is it that it has three different ways of communicating information back: an out
parameter, a return value
and a result
and i am not sure how to work with that as
i getting a
java.sql.SQLException: Parameter #7 has not been set
what is my 7th param and how exactly should i decalre it? to 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 have the SP as folowing
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
what i had been trying so far
String query = "{call [system].[usp_validateUserLogin](?,?,?,?,?)}";
gaved me
The executeQuery method must return a result
cs.setNull(7, Types.NULL);
then i gets a
java.sql.SQLException: Procedure or function usp_validateUserLogin has too many arguments specified.
cs.setInt(5, 1);
still the sameResultSet rs = cs.executeQuery();
instead of
boolean firstResultIsResultSet = cs.execute();
CallableStatement
only worked if they took out the braces{ }
from the query. Don't know if it will help, but it (probably) won't hurt to try.cs.Execute
twice. Not the cause of the error, in all likelihood, but probably not what's intended either. On what line, exactly, are you getting the error?