与我的SQL删除查询不一致。

huangapple 未分类评论44阅读模式
英文:

Inconsistencies with mySQL delete query

问题

我遇到了关于SQL查询结果的一些不一致性问题。

以下是我正在使用的预处理语句查询。

delete ROLE_USER_MAP 
from ROLE_USER_MAP inner join ROLE_MANAGER on ROLE_USER_MAP.R_ID=ROLE_MANAGER.R_ID 
where ROLE_USER_MAP.U_ID= ? and ROLE_MANAGER.M_ID= ?

以下是我在Java应用程序中调用预处理语句的方式。

public void deleteRoles(String mID, String uID) throws OperationFailedException
{
    Connection conn = null;
    try
    {
        conn = this.getConnection();
        this.deleteRoles(mID, uID, conn);
    }
    catch (Exception e)
    {
        AdminLogger.error(this.getClass(), e);
        throw new OperationFailedException("无法删除用户的角色。");
    }
    finally
    {
        try
        {
            conn.close();
        }
        catch (Exception e)
        {
        }
    }
}

private void deleteRoles(String mID, String uID, Connection conn) throws SQLException
{
    PreparedStatement stmt = null;
    try
    {
        stmt = *retrieving ps*
        stmt.setString(1, uID);
        stmt.setString(2, mID);

        int i = stmt.executeUpdate();    // 这里返回 1

        if (i < 1)
        {
            throw new SQLException("无法删除用户的角色。");
        }
    } finally
    {
        stmt.close();
    }
}

在本地和SSMS中运行良好,所有符合where子句的行都被删除,但是当我尝试部署到托管服务器时,只有表中的第一行被删除。

有谁可以帮我解决这个问题吗?

提前感谢您的帮助。

英文:

I've encountered an some inconsistencies regarding the results from an SQL query.

Here is the query which I'm using as a prepared statement.

delete ROLE_USER_MAP 
from ROLE_USER_MAP inner join ROLE_MANAGER on ROLE_USER_MAP.R_ID=ROLE_MANAGER.R_ID 
where ROLE_USER_MAP.U_ID= ? and ROLE_MANAGER.M_ID= ?

Here is how I calling the prepared statement in my Java application.

public void deleteRoles(String mID, String uID) throws OperationFailedException
    {
        Connection conn = null;
        try
        {
            conn = this.getConnection();
            this.deleteRoles(mID, uID, conn);
        }
        catch (Exception e)
        {
            AdminLogger.error(this.getClass(), e);
            throw new OperationFailedException(&quot;Failed to remove roles for user.&quot;);
        }
        finally
        {
            try
            {
                conn.close();
            }
            catch (Exception e)
            {
            }
        }
    }
    
    private void deleteRoles(String mID, String uID, Connection conn) throws SQLException
    {
        PreparedStatement stmt = null;
        try
        {
            stmt = *retrieving ps*
            stmt.setString(1, uID);
            stmt.setString(2, mID);

            int i = stmt.executeUpdate();    // returns 1 here

            if (i &lt; 1)
            {
                throw new SQLException(&quot;Failed to remove roles for user.&quot;);
            }
        } finally
        {
            stmt.close();
        }
    }

It runs fine locally and in SSMS with all rows fitting the where clause being deleted but when I try to deploy it to my hosted server, only the first row in the table is being deleted.

Can anyone help me with this?

Thanks in advance.

huangapple
  • 本文由 发表于 2020年4月7日 15:26:55
  • 转载请务必保留本文链接:https://java.coder-hub.com/61074812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定