Java SELECT @@Identity in Jackcess

Light :

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.

Gord Thompson :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=147412&siteId=1