jdbc - Java SQL Resultset retrieval order is not correct -


hi have following 3 row in table tb1

key   time   id   rowid x     11:40  1      1 y     4:50   1      2 z     6:48   1      2  

now using jdbc records , iterating on resultset shown below:

rs = statement.executequery("select * tb1") resultsetmetadata md = rs.getmetadata(); int cols = md.getcolumncount(); while(rs.next()) {    for(int = 1; <= cols ; i++)    {      system.out.println("col name " + md.getcolumnname(i));      system.out.println("col name " + rs.getobject(i));    }  } 

when execute above code strangely prints second row first , first row , third row. in short resultset data retrieval not in order. dont understand why? please guide. in advance.

you have not specified "order by" clause. in general, databases not required return rows in order unless "order by" clause specified. add order clause select statement.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -