特定の回数ループしてデータベースに挿入するセレンを使用してJavaサーブレットを作成しています。しかし、ループは1回のINSERT後に停止します。
while(i < x)
{
i++;
if(rs.next())
{
String st = rs.getString("st");
String ACCOUNT = rs.getString("User");
String link_URL = rs.getString("Link");
String objectKey = rs.getString("Key");
String DESC = "File description.";
String INF_DESC = " this is an unsual from";
WebElement acc = wait.until(ExpectedConditions.elementToBeClickable(By.id("web_account_"+i)));
WebElement desc = driver.findElement(By.id("web_original_"+i));
WebElement inf_desc = driver.findElement(By.id("web_se_"+i));
WebElement _url = driver.findElement(By.id("web_url_"+i));
List<WebElement> link_in_ = driver.findElements(By.name("web_target_"+i));
WebElement link_in__1 = driver.findElement(By.id("web_website_direct_"+i));
WebElement link_in__conf = driver.findElement(By.id("web_website_direct_confirm_"+i));
WebElement report_another = driver.findElement(By.id("more_link"));
acc.sendKeys(ACCOUNT);
top("Account: ", ACCOUNT, complete, response, 1);
desc.sendKeys(DESC);
top("Description: ", DESC, complete, response, 1);
inf_desc.sendKeys(INF_DESC);
top("Inf_Des: ", INF_DESC, complete, response, 1);
_url.sendKeys(link_URL);
top("URL: ", link_URL, complete, response, 1);
for(WebElement RadioOption : link_in_)
{
//if(RadioOption.getAttribute("value").equals("website"))
if("website".equals(RadioOption.getAttribute("value")))
RadioOption.click();
top("Radio in URL: ", clicked, complete, response, 1);
}
link_in_1.click();
top("Radio in URL2: ", clicked, complete, response, 1);
link_in_conf.click();
top("Radio URL3 Conf: ", clicked, complete, response, 1);
//store current webs in a temp table
st.executeUpdate("INSERT INTO temp_webs (ObjectKey) VALUES ('" + objectKey + "')");
if(i != x)
{
report_another.click();
writer.println("<tr><td>Report Another:</td><td colspan=\"2\">Click</td><td>Complete</td></tr>");
}
}
else
{
writer.println("There was an error in the MySQL query! ID:26");
}
}
問題は、st.executeUpdate("INSERT INTO temp_webs (ObjectKey) VALUES ('" + objectKey + "')");
がループの継続を妨げていることです。このコード行を削除すると、完全に正常に動作します。
更新 クエリが機能し、すべてが正しいことを確認しました。私の問題は、レコードを 1 つだけ挿入してから while ループを終了することです。
UPDATE 2
try catch でクエリを使用した後に新しいエラーが発生しました
Operation not allowed after ResultSet closed
。ループを完了する前に ResulSet が閉じているようです。何が原因かわかりません。