java - use resultset in a for loop -


int = 0; while (i < size) {     string s = username[i];      string sql4 = "select books1,books2 " + uname + "a," + s + "b " + uname + "a.books1=" + s + "b.books2";     resultset rs3 = con.createstatement().executequery(sql4);      system.out.println(sql4);     while (rs3.next()) {          count = rs3.getrow();     }     i++;     system.out.println(count); 

after running code output should 2,1,0,0 instead output 2,2,2,2.that sql query i=0

use resultset.last() instead of while loop. see following example.

count = rs3.last() ? rs3.getrow() : 0; 

bad practices of code

additionally seems bad statements of code. executing query, inside loop make worse program in performance. can use sql queries using count, join , techniques output , efficiently less code.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -