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

查看:295
本文介绍了在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开头索引元素,并使用零来表示空集或空集。

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.

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

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