When I am trying to insert 8 rows using for loop the result varies between 2 - 8 rows per execution
Example
in 1st Execution 7 rows inserted instead of 8 into the database
in 2nd Execution 8 rows inserted into the database (which i want in every execution)
in 3rd Execution 3 rows inserted instead of 8 into the database
This is my code
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();
}
here numbers is an arraylist which contains 8 random numbers.
in 1st query i'm inserting data from table temp to sorted_table
in 2nd query i'm updating the last inserted row
in 3rd query i'm updating the rows using where clause
During execution There are no errors or warnings
Aucun commentaire:
Enregistrer un commentaire