I I have a table table1
like this in MySQL Db without primary key:
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| value | varchar(25) | YES | | NULL | |
| my_date | date | YES | MUL | NULL | |
| my_time | time | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
Is it possible, after to sort the table by my_date and my_time value, update id value start from a given value ?
For example from this set of value
+------+------------+----------+
| id | my_date | my_time |
+------+------------+----------+
| 0 | 2018-03-01 | 09:02:00 |
| 0 | 2018-03-01 | 09:01:00 |
| 0 | 2018-03-01 | 09:00:00 |
+------+------------+----------+
I want to obtain
+------+------------+----------+
| id | my_date | my_time |
+------+------------+----------+
| 100 | 2018-03-01 | 09:00:00 |
| 101 | 2018-03-01 | 09:01:00 |
| 102 | 2018-03-01 | 09:02:00 |
+------+------------+----------+
I have tried something like this without success:
try {
int idFromToStart = 100;
String query = "SELECT IFNULL(id, 0) FROM table1 WHERE my_date > '2018-02-28' order by my_date, my_time";
preparedStatement =con.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = preparedStatement.executeQuery(query);
System.out.println("query " + query);
if (rs.next()) {
rs.updateLong(1, idFromToStart);
System.out.println("rs.getLong(1)) "+rs.getLong(1)+ " idFromToStart "+idFromToStart);
idFromToStart++;
}
} catch (SQLException ex) {
System.out.println("Error db " + ex.getMessage() + " " + ex.toString());
}