• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data is not comming in order as it stored in database

 
santosh kimothi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am having a student table in oracle database...

but when i am retrieving the data from this table by using resultset and jdbc connection. the rows retrieved by resultset are not comming in order, means according to logic first, first row should come, after that second and so on...

but here this order is not predictable, sometime while displaying the output its not following the order...

code is like this....

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select sno from student");
StudentBean studentBean = new StudentBean();
while(resultSet.next())
{
studentBean.setStudentId(resultSet.getString(1));
System.out.println(studentBean.getStudentId());

}


and the output is coming like this....
11
16
21
6

and the database student data is like this...
SNO SNAME SAGE SQUALIFICATION SCOURSE
6 f df df f
11 sd f f sdf
21 bhcv cvb cvb b
16 dfg g d fg g

according to this table if we fetch the data it should come in 6,11,21,16 order but its not coming in this order....

i am unable to understand why its happening please help me...

i will be waiting for your reply...
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you explicitely order by a column, the results are not guaranteed to be in any particular order.
 
santosh kimothi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnaks for your reply
i understand now what was wrong with the sql query

thanks once again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic