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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -