2016-10-28 87 views
0

,所以我的第40位意外的參數標記

得到一個

意外的參數標記,當我嘗試運行我的存儲過程 這是

BEGIN //line 40 
    RETURN 1010 
    END 

我不完全確定那是幹什麼的,如果它與我在代碼中代表值的方式有關代碼

protected String doInBackground(String... params) { 
     if (userid.trim().equals("Developer")|| password.trim().equals("Dev!n_234")) 
      isSuccess2=true; 
     z = getString(R.string.login_succes); 
     if(userid.trim().equals("")|| password.trim().equals("")) 
      z = getString(R.string.indsæt_rigtigt_bruger); 
     else 
     { 
      try { 
       Connection con = connectionClass.CONN(); 
       if (con == null) { 
        z = getString(R.string.Forbindelses_fejl)+"L1)"; 

       } else { 
        String query = "{call [system].[usp_validateUserLogin](?,?,?,?,?)}"; 
        CallableStatement ps = con.prepareCall(query); 
        ps.setString(1, userid); 
        ps.setString(2, password); 
        ps.setInt(3,72); 
        ps.setNull(4, Types.BOOLEAN); 
        ps.registerOutParameter(5, Types.VARCHAR); 
        ps.executeUpdate(); 
        Statement stmt = con.createStatement(); 
        ResultSet rs = stmt.executeQuery(query); 
        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)+"L2)"; 
       Log.e("MYAPP", "exception", ex); 
      } 
     } 
     return z; 

    } 
} 
} 

存儲過程

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 = 'TESTAUTHENTICATIONTICKET' 

     IF (@p_OutDetails = 1) 
     BEGIN 
      SELECT * 
      FROM #tmpLogin 
     END 

     RETURN 0 
    END 

我的舊代碼

protected String doInBackground(String... params) { 
if(userid.trim().equals("")|| password.trim().equals("")) 
z = "Please enter User Id and Password"; 
else 
{ 
try { 
Connection con = connectionClass.CONN(); 
if (con == null) { 
z = "Error in connection with SQL server"; 
} else { 
String query = "select * from Usertbl where UserId='" + userid + "' and password='" + password + "'"; 
Statement stmt = con.createStatement(); 
ResultSet rs = stmt.executeQuery(query); 

if(rs.next()) 
{ 

z = "Login successfull"; 
isSuccess=true; 
} 
else 
{ 
z = "Invalid Credentials"; 
isSuccess = false; 
} 

} 
} 
catch (Exception ex) 
{ 
isSuccess = false; 
z = "Exceptions"; 
} 
} 
return z; 
} 
} 
+0

不能確定您的SP中是否有錯誤,但我更願意將我的返回碼保存在一個RC變量中,並且只在返回此RC的SP末尾進行一次退出。 –

+0

SP中不應該有任何錯誤,因爲它正在處理我們的主程序 –

+0

我假設「位置40」是查詢字符串中的字符位置(圓括號開始處)。這是肯定的客戶端錯誤,你的sp不會被執行。注意,你在'prepareCall'之前調用'executeQuery'。 –

回答

0

似乎有這裏有一些問題。正如Ivan Starostin指出的那樣,您在prepareCall之前撥打executeQuery。另外:

CallableStatement cs = null; // This variable is cs 
String query = "{call [system].[usp_validateUserLogin] (?,?,?,?,?)}"; 
Statement stmt = con.createStatement(); 
ResultSet rs = stmt.executeQuery(query); // I assume the error is here because you're executing an empty statement 
CallableStatement ps = con.prepareCall(query); // Then you make another CallableStatement called ps 
ps.setString(1, userid); 
// other stuff with ps 
cs.executeUpdate(); // Then you ignore ps and call cs, which is null 

一個你需要作爲一個程序員的技能是看你的代碼一行一行地弄清楚它做什麼的能力。如果你仔細查看了你的代碼,你應該看到這些問題。我不是故意要苛刻,只是想讓你在未來考慮如何處理這些問題,因爲他們會一遍又一遍地出現。每個人都會犯錯誤編碼,這沒什麼大不了的,我們只需要學習如何在出現問題時發現它們。

+0

我試圖解決它,並改變CS爲PS gaved我同樣的錯誤,並移動'語句stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query);'在執行update之後更新gaved me空指針或僅使用ResultSet rs = ps.executeQuery(query);' 此類型不支持使用executeQuery(String)方法的聲明 所以我abit在這裏丟失 問題是,我有它在我的舊代碼中運行沒有任何問題,我輸入的聲明,但我試圖從我們的SP做到這一點,我不知道如何讓它與我的結構一起工作 –

+0

聽起來好像你只是在嘗試一些事情而不理解他們做什麼。你知道你的方法中的每一行是什麼嗎? – nasch