In JDBC, why do parameter indexes for prepared sta

2019-01-17 10:08发布

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?

6条回答
萌系小妹纸
2楼-- · 2019-01-17 10:44

I understand both JDBC and ODBC are based upon the X/Open Call Level Interface. So, it's pre-Java history, like 0-based month numbers.

查看更多
We Are One
3楼-- · 2019-01-17 10:50

More human friendly maybe? Also, Java's regular expression Matcher's group starts with 1 as the first matched group.

查看更多
疯言疯语
4楼-- · 2019-01-17 10:51

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.

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.

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

查看更多
相关推荐>>
5楼-- · 2019-01-17 10:52

Personally I would chalk this up to bad design.

查看更多
干净又极端
6楼-- · 2019-01-17 10:55

Likely it's that JDBC was modeled on ODBC.

查看更多
放我归山
7楼-- · 2019-01-17 10:56

This was part of a plot by the original language designers to weed out the weak. In the original spec, arrays were numbered from -1, and lists with 1 element returned length =0.

Today, only the java Calendar API remains from this diabolical plot.

查看更多
登录 后发表回答