【发布时间】:2017-09-22 19:58:25
【问题描述】:
我在数据库中有一些表。他们有一些特定的模式。例如,假设我有表员工,然后是其他具有相同模式的表,例如:
table 1:employee
table 2:employee_X
table 3:employee_Y
我想检查这些表是否包含数据,如果它们包含,那么我必须为每个表调用一些方法。我正在使用以下代码进行检索。
DatabaseMetaData meta = con.getMetaData();
ResultSet res = meta.getTables(null, null, "My_Table_Name", new String[] {"TABLE"});
while (res.next()) {
if(rs.getStrin(3).equals(employee)){
//my code to write data of this table to a file
}
if(rs.getString(3).equals(employee_X)){
//my code to write data to the same file
}
if(rs.getString(3).equals(employee_Y)){
//code to write data to the same file from this table
}
}
代码运行良好,但我如何一次从所有这些表中检索数据,而不是使用三个检查。如果这些表中的任何一个包含我想将其写入我的文件的数据。如何以更少的代码行高效地执行此操作?
如果有人能提出方法来检查这些表中的每一个是否包含数据,那就太好了,然后我可以调用我的代码将数据写入文件。
【问题讨论】: