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 に答える