使用JtdsPreparedStatement.execute执行一个insert语句时会报“拒绝了对对象 'xp_cmdshell' (数据库 'mssqlsystemresource',架构 'sys')的 EXECUTE 权限”错误,看了半天源码没找到原因,从源码里看它并没有发送需要用到xp_cmdshell的语句,求高手指教到底是怎么回事情。

解决方案 »

  1.   


    int i;
            i = 0;
            PreparedStatement pstmt = null;
            try
            {
                if(conn == null)
                    throw new SException("\u6570\u636E\u5E93\u8FDE\u63A5\u4E3A\u7A7A");
                pstmt = conn.prepareStatement(SqlProc.exchangSql(sql));
                SqlProc.setParameters(pstmt, sql, obj);
                pstmt.execute();
                i = pstmt.getUpdateCount();
            }
            catch(Exception e)
            {
                throw new SException(getClass().getName()+"\u6570\u636E\u5E93\u64CD\u4F5C\u5931\u8D25\uFF1A" + sql, e);
            }
            finally
            {
                closePstmt(pstmt);
            }
            return i;这个pstmt.execute()代码执行就报这个错误。SqlProc.setParameters(pstmt, sql, obj);是一个把对象转为PreparedStatement参数的方法。只要给数据库用户执行xp_cmdshell的权限语句就能正常执行。
      

  2.   

    但是执行insert语句不需要用到xp_cmdshell吧。
      

  3.   

    现在情况就是这样的,必须要数据库用户拥有执行xp_cmdshell的权限(即已经有在服务器上创建Windows用户的权限)才能执行一条insert插入。是因为Jtds的配置不对还是什么原因造成的呢。
      

  4.   

    使用PreparedStatement时,有没有什么错误会导致SqlServer自动调用xp_cmdshell来处理?