0

我正在尝试用 Java 制作一个 sql 过程。

我必须用Java制作程序的原因是,程序一旦创建就会被锁定。

因此,当我需要进行一些修改时,我必须删除整个程序并重新创建一个

Java中的过程。

这可能吗?还是我应该找到不同的方法来做到这一点?

谢谢阅读

4

1 回答 1

1

As long as the user that your code is using to connect to the DB has the correct permissions then you should just be able to execute the normal SQL to create the SP. Nothing special needed to do it from Java. Here are the permissions you need:

Permissions Requires CREATE PROCEDURE permission in the database and ALTER permission on the schema in which the procedure is being created.

An example of the SQL is:

USE AdventureWorks2012;
GO
CREATE PROCEDURE HumanResources.uspGetEmployeesTest2 
    @LastName nvarchar(50), 
    @FirstName nvarchar(50) 
AS 

    SET NOCOUNT ON;
    SELECT FirstName, LastName, Department.
    FROM HumanResources.vEmployeeDepartmentHistory
    WHERE FirstName = @FirstName AND LastName = @LastName
    AND EndDate IS NULL;
GO

Warning Let me also say that this is a generally bad idea to run an application this way. It's just so easy for something to go terribly wrong and your application does something crazy like delete a whole table. Just be careful with this especially if your application gets any input from a user. This is risky.

于 2012-07-09T05:06:32.633 回答