UCanAccess读取表的最后一列作为第一列 [英] UCanAccess reads the last column of a table as the first column

查看:173
本文介绍了UCanAccess读取表的最后一列作为第一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序始终将Access数据库的第一列读取为第二列,将第二列读取为第三列,依此类推,但它将最后一列读取为第一列.

My program always reads the first column in the Access database as the 2nd column, the 2nd one as the 3rd column and so on, but the last column it reads as the first column.

public void actionPerformed(ActionEvent e) {
  try{
    String query = "insert into Staff values ('2', 'w', 'w', 'w', 'e', 'w', 'd','d','end')";
    stmt.executeUpdate(query);
    status.setText("1 row of record have been inserted");
  }catch(Exception ex){
    ex.printStackTrace();
  }
}

但是当我指定列名时,它会正常读取

But when i specify the column names, it reads normally

public void actionPerformed(ActionEvent e) {
  try{
    String query = "insert into Staff (id, lastName, firstName, mi, address, city, state, telephone, email) "
    + "values ('2', 'w', 'w', 'w', 'e', 'w', 'd','d','end')";
    stmt.executeUpdate(query);
    status.setText("1 row of record have been inserted");
  }catch(Exception ex){
    ex.printStackTrace();
  }
}

推荐答案

默认情况下,UCanAccess以"DATA"顺序处理表的列.这是在Access元数据中内部定义列的顺序,可以与"DISPLAY"顺序不同.

By default, UCanAccess treats the columns of a table in "DATA" order. That is the order in which the columns have been defined internally in the Access metadata, which can be different from the "DISPLAY" order.

如果您希望UCanAccess以"DISPLAY"顺序处理列,请添加参数

If you want UCanAccess to treat the columns in "DISPLAY" order, then add the argument

;columnOrder=DISPLAY

连接URL的末尾,例如

to the end of your connection URL, e.g.,

jdbc:ucanaccess://c:/db/cico.mdb;columnOrder=DISPLAY

但是,您现在还应该意识到,通过 not 在IN​​SERT语句中指定实际的列名,您可以通过假设名称来使代码易于损坏(和顺序).

However, you should also realize by now that by not specifying the actual column names in your INSERT statement you are leaving your code vulnerable to breakage by assuming the names (and order) of the columns.

就像SELECT * FROM一样被皱眉,INSERT INTO tablename VALUES ( ...也一样.您已经为每列指定了 values ,因此您实际上也应该指定各列的 names .

Just as SELECT * FROM is frowned upon, so is INSERT INTO tablename VALUES ( .... You are already specifying the values for each column so you really should be specifying the names of the columns as well.

这篇关于UCanAccess读取表的最后一列作为第一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆