gpt4 book ai didi

java servlet while循环用mysql INSERT INTO缩短

转载 作者:行者123 更新时间:2023-11-30 01:12:55 24 4
gpt4 key购买 nike

我正在使用selenium制作一个java servlet,它循环一定次数并插入到数据库中。但循环在 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 + "')"); 阻止循环继续。当我删除这行代码时,它工作得很好。

更新我已确认查询有效且一切正确。我的问题是它只插入一条记录,然后退出 while 循环。

更新两个在 try catch 中使用查询后出现新错误ResultSet 关闭后不允许进行操作看来 ResulSet 在完成循环之前关闭。不确定什么会导致这种情况。

最佳答案

解决方案是创建一个新的语句连接并在循环内使用新的连接。它停止的原因是因为连接在第一个循环后被关闭。

关于java servlet while循环用mysql INSERT INTO缩短,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19323327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com