ghassen92
ghassen92

Reputation: 305

update database java

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.

Upvotes: 2

Views: 104

Answers (2)

Brent Worden
Brent Worden

Reputation: 10974

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

Upvotes: 1

Vivek Sadh
Vivek Sadh

Reputation: 4268

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.

Upvotes: 1

Related Questions