以下は私の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
各テーブルのそれぞれに 1 つの列名しか表示されません。
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
か?