,所以我的第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; } }
不能確定您的SP中是否有錯誤,但我更願意將我的返回碼保存在一個RC變量中,並且只在返回此RC的SP末尾進行一次退出。 –
SP中不應該有任何錯誤,因爲它正在處理我們的主程序 –
我假設「位置40」是查詢字符串中的字符位置(圓括號開始處)。這是肯定的客戶端錯誤,你的sp不會被執行。注意,你在'prepareCall'之前調用'executeQuery'。 –