下面是我的config.property file
TABLES: table1 table2
#For Table1
table1.url: jdbc:mysql://localhost:3306/garden
table1.user: gardener
table1.password: shavel
table1.driver: jdbc-driver
table1.percentage: 80
table1.column: column1
table1.column: column2
table1.column: column3
#For Table2
table2.url: jdbc:mysql://otherhost:3306/forest
table2.user: forester
table2.password: axe
table2.driver: jdbc-driver
table2.percentage: 20
table2.column: column1
table2.column: column2
table2.column: column3
下面是我的代码,我在其中尝试读取上面的属性文件并ReadTableConnectionInfo
通过使用不同的值填充它来创建对象,但不知何故,列 HashSet 没有填充与每个表对应的所有列名。columns HashSet
我在每个表中只看到一个列名。
private static void readPropertyFile() throws IOException {
prop.load(Read.class.getClassLoader().getResourceAsStream("config.properties"));
tableNames = Arrays.asList(prop.getProperty("TABLES").split(" "));
for (String arg : tableNames) {
ReadTableConnectionInfo ci = new ReadTableConnectionInfo();
String url = prop.getProperty(arg + ".url");
String user = prop.getProperty(arg + ".user");
String password = prop.getProperty(arg + ".password");
String driver = prop.getProperty(arg + ".driver");
String table = prop.getProperty(arg + ".table");
double percentage = Double.parseDouble(prop.getProperty(arg + ".percentage"));
String columnPrefix = arg + ".column";
HashSet<String> columns = new HashSet<String>();
for (String key : prop.stringPropertyNames()) {
if (key.startsWith(columnPrefix))
columns.add(prop.getProperty(key));
}
ci.setUrl(url);
ci.setUser(user);
ci.setPassword(password);
ci.setDriver(driver);
ci.setTableName(table);
ci.setPercentage(percentage);
ci.setColumns(columns);
tableList.put(arg, ci);
}
}
我在这里填充列 HashSet 然后将列 HashSet 添加到这里有什么问题ReadTableConnectionInfo class
吗?