Click Here For Output Image当我尝试使用for循环插入8行时,结果在每次执行2到8行之间变化
实施例
第一次执行中的将7行而不是8行插入数据库
第二次执行中的插入数据库的8行(每次执行时都需要)
在第3次执行中 将3行而不是8行插入数据库
这是我的代码
try {
for(int g = 0; g < 8 ; g++)
{
sql = String.format("insert into Sorted_Table (marks,category,books,subject,lesson,medium,school_books,questions,standard,image,image1,image2,fimage,exercise,year,status,ans,ans1) select * from Temp where rowid = %d",numbers.get(g));
pst=con.prepareStatement(sql);
pst.executeUpdate();
sql = String.format("update Sorted_Table SET qno = '%d',attempt = '%d',total = '%d',subqn = '%s' where rowid = (select max(rowid) from Sorted_Table) ",4,1,1,'B');
pst=con.prepareStatement(sql);
pst.executeUpdate();
sql = String.format("update Sorted_Table SET attempts = '%s',totals = %d where qno = '%d' and subqn = '%s' ",'5',8,4,'B');
pst=con.prepareStatement(sql);
pst.executeUpdate();
}
}
catch(Exception f)
{
f.printStackTrace();
}
这里的数字是一个包含8个随机数的arraylist。
在第一个查询中我将表temp中的数据插入到sorted_table
在第二个查询中我正在更新最后插入的行
在第三个查询中我正在使用where子句
更新行执行期间没有错误或警告
*检查图像输出