且构网

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

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

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

过去,数据库对绑定参数使用基于 1 的索引.这大概反映了集合论和数学中关系数据库的起源,即索引元素以1开头,用0表示空集或空集.

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 脚本的情况下,第零个参数"实际上是被调用的命令.

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.