*
The moose likes JDBC and the fly likes data is not comming in order as it stored in database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "data is not comming in order as it stored in database" Watch "data is not comming in order as it stored in database" New topic
Author

data is not comming in order as it stored in database

santosh kimothi
Ranch Hand

Joined: Jun 10, 2009
Posts: 32
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...


Santosh Kimothi,
Java programmer
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Unless you explicitely order by a column, the results are not guaranteed to be in any particular order.


Thanks and Regards
santosh kimothi
Ranch Hand

Joined: Jun 10, 2009
Posts: 32
thnaks for your reply
i understand now what was wrong with the sql query

thanks once again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: data is not comming in order as it stored in database
 
Similar Threads
resultset is not working properly
long post IBM.158
Help with my homework please
servlets and xml