JDBC连接的语法prepareCall SQL [英] Syntax of JDBC Connection prepareCall SQL

查看:201
本文介绍了JDBC连接的语法prepareCall SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读用于 Connection#prepareCall

I am reading the JavaDocs for Connection#prepareCall:


sql - 一个SQL语句,可能包含一个或多个'?'参数占位符。通常使用JDBC调用转义语法指定此语句。

sql - an SQL statement that may contain one or more '?' parameter placeholders. Typically this statement is specified using JDBC call escape syntax.

根据这个流行的 mkyong JDBC tutorial ,我看到这样执行的方法如下:

According to this popular mkyong JDBC tutorial, I see the method executed like so:

String insertStoreProc = "{call insertDBUSER(?,?,?,?)}";
callableStatement = dbConnection.prepareCall(insertStoreProc);

我想知道:


  1. 为什么字符串封装在花括号中( {...} )?

  2. 为什么致电继续执行程序的名称?

  1. Why is the string encapsulated in curly braces ({ ... })?
  2. Why does call proceed the name of the procedure?

最重要的是 :是 {call< nameOfProcedure> } 在所有JDBC驱动程序中执行所有存储过程的正确语法?或者是 {call ...} 特定于特定类型的驱动程序?

Most importantly: is { call <nameOfProcedure> } the correct syntax for executing all stored procedures across all JDBC drivers? Or is { call ... } specific to a particular type of driver?

此程序是否有变化调用语法?例如,是否存在可以将{execute< nameOfProcedure>}传递到 prepareCall 的情景/驱动程序方法?有没有这方面的文件?

Are there variations of this procedure invocation syntax? For instance, are there scenarios/drivers where one might pass "{ execute <nameOfProcedure> }" into the prepareCall method? Is there documentation on any of this?

根据 CallableStatement ,JDBC在所有驱动程序中以标准方式为调用proc提供了2种有效语法:

According to CallableStatement, JDBC offers 2 valid syntaxes for calling procs in a standard way, across all drivers:

{?= call <procedure-name>[(<arg1>,<arg2>, ...)]}

并且:

{call <procedure-name>[(<arg1>,<arg2>, ...)]}

但它是还不清楚何时使用(即:何时预先发送使用调用?= )。

But it is still unclear as to when to use either (that is: when to preprend call with ?=).

推荐答案

JDBC规范,第13.4节Escape语法定义了许多名为JDBC转义的转义。这些逃脱用花括号包裹。调用转义的规范是:

The JDBC specification, section 13.4 Escape Syntax defines a number of escapes called JDBC escapes. These escapes are wrapped in curly braces. The specification for the call escape is:


如果数据库支持存储过程,可以使用JDBC转义语法调用它们,如下所示:

If a database supports stored procedures, they can be invoked using JDBC escape syntax as follows:

{call <procedure_name> [(<argument-list>)]}

或者,如果过程返回结果参数:

or, where a procedure returns a result parameter:

{? = call <procedure_name> [(<argument-list>)]}

方括号表示(参数列表) )部分是可选的。输入参数可以是文字或参数标记。有关参数的信息,请参见第108页的设置参数。

The square brackets indicate that the (argument-list) portion is optional. Input arguments may be either literals or parameter markers. See "Setting Parameters" on page 108 for information on parameters.

这也记录在 java.sql.CallableStatement

This is also documented on java.sql.CallableStatement

因此名称调用并且大括号都在JDBC规范中指定。

So the name call and the curly braces are both specified in the JDBC specification.

关于问题的第二部分。 JDBC是一种尽可能尝试与数据库无关的规范,并且通常 - 默认为SQL标准。 IIRC SQL规范指定存储过程没有返回值或单个返回值。如果存储过程没有返回值,则使用第一个调用语法。如果存储过程有一个返回值,那么你使用第二个。

As to the second part of your question. JDBC is a specification that tries to be database independent as much as possible and to do this it - usually - defaults to the SQL standard. IIRC the SQL specification specifies that a stored procedure either has no return value or a single return value. If the stored procedure has no return value, then you use the first call syntax. If the stored procedure has a single return value, then you use the second.

存储过程也可以有 OUT 参数(不要与结果集混淆),这些参数在普通参数列表中定义。

Stored procedures can also have OUT parameters (not to be confused with result sets), which are defined in the normal argument list.

这篇关于JDBC连接的语法prepareCall SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆