简体   繁体   中英

Java SELECT @@Identity in Jackcess

I try use Jackcess to get id of the last added row. In java or vba i can use SELECT @@Identity. In Jackess java print mi this information:

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

I get this information:

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

But i no have idea how i can get "lastAutoNumber" to Integer, String or any use varible. Jackess doc and google did not help.

The Jackcess documentation for Table#addRow says:

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).

So,

// 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);

ref: here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM