Slide 5
Slide 5 text
❏ 実装したプログラムの概要は以下の通り
問題の実装コードと実行コマンド
public static void main(String[] args) throws SQLException {
List updateAttributes = null;
try (Connection con = DriverManager.getConnection(connectionUrl, "user", "pass")) {
updateAttributes = new ArrayList<>();
String sql1 = "SELECT id,name,address FROM TABLE_A WHERE
address is NULL";
PreparedStatement stmt1 = con.prepareStatement(sql1);
ResultSet rs1 = stmt1.executeQuery(sql1);
// SELECT したすべてのデータを List に格納
while (rs1.next()) {
updateAttributes.add(new UpdateAttribute(rs1.getInt("id"), rs1.getString("name"), null));
}
for (UpdateAttribute updateAttribute : updateAttributes) {
// List をループして更に別テーブルに SELECT 文を実行
while (rs2.next()) {
// なんらかの業務ロジック
… 省略
}
public static void main(String[] args) throws SQLException {
… 省略
for (UpdateAttribute updateAttribute : updateAttributes) {
// List をループして更に別テーブルに SELECT 文を実行
while (rs2.next()) {
// なんらかの業務ロジック
...
String sql3 = "SELECT name,address FROM TABLE_B WHERE
name='" + <ロジックから取得できた値> + "'";
while (rs3.next()) {
// なんらかの業務ロジック
...
updateAttribute.setAddress(rs3.getString("address"));
}
}
}
// SQL ファイル出力処理
...
} catch () … // 例外処理
}