java API运行sql脚本

时间:2012-11-08 09:49:08

标签: java sql jdbc

可以使用哪些Java API来运行sql脚本。如何在以下脚本中以类似脚本的方式读取访问数据库的进程中的某些数据。

DECLARE @DatabaseName nvarchar(50)
DECLARE @SPId int
DECLARE @SQL nvarchar(100)

 SET @DatabaseName = N<dbname>

DECLARE my_cursor CURSOR FAST_FORWARD FOR
SELECT SPId FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId

OPEN my_cursor

FETCH NEXT FROM my_cursor INTO @SPId

WHILE @@FETCH_STATUS = 0
BEGIN
 SET @SQL = 'KILL ' + CAST(@SPId as nvarchar(10))
 print @SQL
EXEC sp_executeSQL @SQL


 FETCH NEXT FROM my_cursor INTO @SPId
END

CLOSE my_cursor
DEALLOCATE my_cursor 

GO

DROP DATABASE <dbname>
GO 

0 个答案:

没有答案