gpt4 book ai didi

Jackcess 中的 Java SELECT @@Identity

转载 作者:行者123 更新时间:2023-11-30 07:42:17 24 4
gpt4 key购买 nike

我尝试使用 Jackcess 获取最后添加的行的 ID。在 java 或 vba 中我可以使用选择@@Identity。在 Jackess java 中打印 mi 这个信息:

Column c = table.getPrimaryKeyIndex().getColumns().get(0).getColumn();
System.out.println(c);

我得到这个信息:

Column@3b398b29[
name: (RatingGeneral) ID
type: 0x4 (LONG)
number: 0
length: 4
variableLength: false
lastAutoNumber: 155
]

但我不知道如何将“lastAutoNumber”转换为整数、字符串或任何使用变量。 Jackess 文档和谷歌没有帮助。

最佳答案

Table#addRow 的 Jackcess 文档说:

Note, if this table has an auto-number column, the value generated will be put back into the given row array (assuming the given row array is at least as long as the number of Columns in this Table).

所以,

// table has two columns: id (AutoNumber), and lastname (Text(100))
Table tbl = db.getTable("customer");
Object[] newRow = new Object[] {Column.AUTO_NUMBER, "Thompson" };
tbl.addRow(newRow);
int newId = (int) newRow[0];
System.out.printf("New row was assigned AutoNumber value %d%n", newId);

引用:here

关于Jackcess 中的 Java SELECT @@Identity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54973527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com