update database java

100 views Asked by At

I'm working on database containing 2 columns (NOM (String) ,TMP(integer)). But when I tried to update it , the first row became the last. Can I update it and maintain the same order?

  Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

      ResultSet result = state.executeQuery("SELECT * FROM cities");

      result.absolute(1);
      result.updateString("NOM", "xxx");
      result.updateRow();

enter image description here Here's my databasebefore and after the excution of my code.

2

There are 2 answers

0
Brent Worden On BEST ANSWER

The results are displayed ordered by primary key. Since you changed the primary key nom field the ordering changed as well.

0
Vivek Sadh On

Brent is correct. Normally the results are sorted by primary key in the tables. As you changed the primary key so it is showing the updated order.