简体   繁体   English

有什么办法可以从Java代码在.sql文件中执行存储过程

[英]Is there any way to execute stored procedure in .sql file from java code

I have stored procedure saved on local file system in .sql file. 我已将存储过程保存在.sql文件中的本地文件系统中。 Ex. 防爆。 StoredProcedure.sql StoredProcedure.sql

I am looking for a way to read and execute this stored procedure file from java code. 我正在寻找一种从Java代码读取和执行此存储过程文件的方法。

We can execute database stored procedure using 我们可以使用执行数据库存储过程

    CallableStatement cs = conn.prepareCall("{call ProcedureName(?)}");
    cs.setInt(1, 1);
    cs.execute();

I am looking for way to pass "new File(sqlFilePath)" instead of "call ProcedureName" 我正在寻找传递“新File(sqlFilePath)”而不是“ call ProcedureName”的方法

Sample Contents of StoredProcedure.sql StoredProcedure.sql的样本内容

    USE [DBName]
    GO
    DECLARE @return_value int

    EXEC    @return_value = [dbo].[ProcedureName]
            @p1 = 1

    SELECT  'Return Value' = @return_value

    GO

You can use the Stored Procedure query directly inside your java code file instead of referring to as sql file. 您可以直接在Java代码文件中使用存储过程查询,而不必将其称为sql文件。

Or you can simply read the content of the file and store it to a variable. 或者,您可以简单地读取文件的内容并将其存储到变量中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM