在 JDBC 中,为什么准备语句的参数索引从 1 而不是 0 开始? [英] In JDBC, why do parameter indexes for prepared statements begin at 1 instead of 0?

查看:22
本文介绍了在 JDBC 中,为什么准备语句的参数索引从 1 而不是 0 开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 的其他任何地方,任何索引都从 0 开始.这里有改变的原因吗,或者这只是糟糕的设计?

Everywhere else in Java, anything with an index starts at 0. Is there a reason for the change here or is this just bad design?

推荐答案

过去,数据库对绑定参数使用基于 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.

这篇关于在 JDBC 中,为什么准备语句的参数索引从 1 而不是 0 开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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