且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JDBC中,为什么预处理语句的参数索引从1开始而不是0?

更新时间:2023-02-19 12:01:30

从历史上看,数据库对绑定参数使用了基于1的索引。这可能反映了集合论和数学中关系数据库的起源,它们以1开头索引元素,并使用零来表示空集或空集。

Historically, databases have used 1-based indexing for bound parameters. This probably reflects the origins of relational databases in set theory and mathematics, which index elements starting with one, and use zero to represent a null or empty set.

在shell脚本中和正则表达式一样,零指数通常意味着特殊。例如,在shell脚本的情况下,第0个参数实际上是被调用的命令。

In shell scripts and regular expressions, the zero index usually means something "special". For example, in the case of shell scripts, the zeroth "argument" is actually the command that was invoked.

JDBC的选择是故意的,但最终可能会导致比它解决的更多的困惑和困难。

The choice for JDBC was deliberate but, ultimately, probably causes more confusion and difficulty than it solves.