java迭代器hasnext方法工作异常
我使用迭代器遍历条目对象列表。它遍历迭代器,初始化preparedStatement对象并将该对象添加到批处理中。当批处理达到特定大小时,它将执行批处理并再次执行该操作。java迭代器hasnext方法工作异常,java,database,iterator,Java,Database,Iterator,我使用迭代器遍历条目对象列表。它遍历迭代器,初始化preparedStatement对象并将该对象添加到批处理中。当批处理达到特定大小时,它将执行批处理并再次执行该操作。以下是我的部分代码: for (Fields field : fieldList) { if(field != null) { if (countField < batchLimit)//check if the batch size lim
以下是我的部分代码:
for (Fields field : fieldList)
{
if(field != null)
{
if (countField < batchLimit)//check if the batch size limit is reached
{
//more items can be added to batch
Iterator<Entry<String, List<String>>> i = field.getParameters();
if (i != null)
{
while (i.hasNext())
{
Entry<String, List<String>> e = i.next();
for (String str : (List<String>) e.getValue())
{
psField.setString(1, field.getField1());
psField.setString(2, field.getField2());
psField.setString(3, str);
psField.addBatch();//add record to batch
psFieldTemp.addBatch();
countField++;
}
}
}
}
else
{
//records in batch will be executed to Database
psField.executeBatch();
psFieldTemp.executeBatch();
countField = 0;
//empty the batch
psField.clearBatch();
psFieldTemp.clearBatch();
}
}
}
例如,如果在迭代器中从两个不同的条目中获取的值类似于“language=java”
,则对于第一个条目,代码会通过条件,而对于第二个条目则不会通过条件。我用Map解决了这个问题,但我想知道为什么会发生这种情况
编辑:我添加了更多的代码。对不起,您必须给出一个详细的说明。还要验证您正在使用的语言。您正在询问Java迭代器,您的问题被标记为JavaScript。@Axel我的代码是用Java编写的。我想标签没问题。您认为还需要哪段代码?我写了这个问题的来源,还带来了一个调试时的例子。如果您提供了最短的编译示例(最好是一个带有
main
方法的类,以及产生您描述的错误的输入),这将非常有帮助。在当前表单中,人们只能猜测您正在尝试将具有相同密钥的两个条目添加到地图中(这将不起作用,因为第二个条目将覆盖第一个条目)。是的!我只是想知道你是如何用Map解决这个问题的@帕兹的问题已被编辑。
while(i.hasnext())