标签:服务器 tostring sys 存在 div 用户 ring user bsp
使用sa帐号登录SQL Server Management Studio,右键点击安全性-登录名-数据库用户名属性,设置服务器角色为sysadmin。
String JOB_BCP_DELETE_SQL = “IF EXISTS (SELECT * FROM sys.objects WHERE name = ‘PROCEDURE_BCP_OUT‘ AND type in (N‘P‘, N‘PC‘))\n DROP PROCEDURE PROCEDURE_BCP_OUT \n”; pre = conn.prepareStatement(JOB_BCP_DELETE_SQL); pre.execute();
String sql = "set @sql = N‘BCP ‘ + @tableName + ‘ out ‘ + @filePath + ‘ -c -t -U \"‘ + @userName + ‘\" -P \"‘ + @password + ‘\" -S \"‘ + @dbIp + ‘\"‘\n"; StringBuffer createSqlBuf = new StringBuffer(); createSqlBuf.append("CREATE PROCEDURE PROCEDURE_BCP_OUT \n") .append("@dbIp nvarchar(256),\n") .append("@userName nvarchar(256),\n") .append("@password nvarchar(256),\n") .append("@tableName nvarchar(256),\n") .append("@filePath nvarchar(256)\n") .append("AS\n") .append("BEGIN\n") .append("EXEC master.sys.sp_configure ‘show advanced options‘, 1\n") .append("RECONFIGURE\n") .append("EXEC master.sys.sp_configure ‘xp_cmdshell‘, 1\n") .append("RECONFIGURE\n") .append("declare @sql nvarchar(256)\n") .append(sql) .append("EXEC master..xp_cmdshell @sql\n") .append("EXEC master.sys.sp_configure ‘show advanced options‘, 1\n") .append("RECONFIGURE\n") .append("EXEC master.sys.sp_configure ‘xp_cmdshell‘, 0\n") .append("RECONFIGURE\n") .append("END"); String createSql = createSqlBuf.toString(); pre = conn.prepareStatement(createSql); pre.execute();
StringBuffer execSqlBuf = new StringBuffer(); execSqlBuf.append("EXECUTE PROCEDURE_BCP_OUT \n") .append("@dbIp=?, ").append("@userName=?, ").append("@password=?, ") .append("@tableName=?, ").append("@filePath=?"); String execSql = execSqlBuf.toString(); pre = conn.prepareStatement(execSql); pre.setString(1, dbIp); pre.setString(2, dbUserName); pre.setString(3, dbPassword); pre.setString(4, tableName); pre.setString(5, file); pre.execute();
标签:服务器 tostring sys 存在 div 用户 ring user bsp
原文地址:https://www.cnblogs.com/aaroncnblogs/p/8861831.html