简体   繁体   English

杰克逊删除行并设置自动增量列

[英]jackcess delete row and set autoincrement column

  1. How delete row from table with help jackcess? 如何使用帮助技巧从表中删除行? I try so, but it's bad: 我尝试这样做,但这很不好:

      Table ptabl = db.getTable("person"); int pcount = ptabl.getRowCount(); for (int i = 0; i < pcount; i++) { Map<String, Object> row2 = ptabl.getNextRow(); if (row2.get("id") == Integer.valueOf(1)) { ptabl.deleteCurrentRow(); } } 
  2. How set column "id" attribute to autoincrement? 如何将列“ id”属性设置为自动增量?

    Table newTable = new TableBuilder("diagnosis"). addColumn(new ColumnBuilder("id") .setSQLType(Types.INTEGER) .toColumn()) .addColumn(new ColumnBuilder("name") .setSQLType(Types.VARCHAR) .toColumn()).toTable(db);

If your id column is indexed, you can use an IndexCursor to quickly find columns: 如果您的id列已建立索引,则可以使用IndexCursor快速查找列:

IndexCursor cursor = new CursorBuilder(ptabl).setIndexByColumnNames("id").toIndexCursor();
if(cursor.findFirstRowByEntry(1)) {
  cursor.deleteCurrentRow();
}

If your id column is not indexed, you can use a normal cursor, which is more convenient but effectively no faster than your current code (just does a table scan): 如果您的id列未建立索引,则可以使用普通的游标,它比当前代码更方便但实际上没有快(表扫描也是如此):

Cursor cursor = new CursorBuilder(ptab1).toCursor();
Column idCol = ptab1.getColumn("id");
if(cursor.findFirstRow(idCol, 1)) {
  cursor.deleteCurrentRow();
}

And your own answer indicates you already figured out how to make a column auto increment. 您自己的答案表明您已经想出了如何使列自动递增的方法。

对于将自动增量设置为列:

Table newTable = new TableBuilder("diagnosis").addColumn(new ColumnBuilder("id").setAutoNumber(true).setSQLType(Types.INTEGER).toColumn()).addColumn(new ColumnBuilder("name").setSQLType(Types.VARCHAR).toColumn()).toTable(db);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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