我从java和jackcess开始,我有这个代码
public class DataManagement {
static Database db;
static Database dbopen;
static Table Users;
static Set<String> tablename;
static String[] nametabla;
public static void opendatabase(){
try {
dbopen=DatabaseBuilder.open(new File("D:/alex.accdb"));
tablename=dbopen.getTableNames();
nametabla = tablename.toArray(new String[0]);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void readtabla (String name){
System.out.println(name);
for(Column column : name.getColumns()) {
String columnName = column.getName();
System.out.println(columnName + " " );
}
}
public static void main(String[] args){
/*opening an existing database*/
opendatabase();
System.out.println("the name of tables are " + tablename);
System.out.println("the name of table 2 is " + nametabla[1]);
readtabla(nametabla[1]);
}
}
没有方法readtabla中的“for”我得到了这个
the name of the tables are [Establecimiento, Estado, Medición, Ubicación]
the name of table 2 is Estado
Estado
问题出在这里
for(Column column : name.getColumns())
因为name必须是(我认为)一个Table类型,我将它作为字符串类型发送,那么如何将字符串类型转换为Table类型? 还是有另一种方式? 提前谢谢
答案 0 :(得分:0)
您可以使用Database对象的getTable()
方法返回Table对象:
public static void readtabla (String name) {
System.out.println(name);
Table tbl;
try {
tbl = dbopen.getTable(name);
for(Column column : tbl.getColumns()) {
String columnName = column.getName();
System.out.println(columnName + " " );
}
} catch (IOException e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
您可以使用jackcess-orm仅操作java POJO