So, I have a local server of MySQL database on my machine and I'm trying to change a TIME column values in one of the database's tables, straight from a Java program.
What I'm trying to do is to fetch all the lines from a table called "Flights" where the source is "Amsterdam" into a ResultSet called rs
, then update the time inside the result row's 2nd column to a value the user inputs, and then update the row inside the DB.
Those are the rows I want to update their 2'nd column TIME:
35 11:38:08 9W8915 Amsterdam Cancelled 4
36 11:38:08 DL9644 Amsterdam Cancelled 4
37 11:38:08 G35516 Amsterdam Cancelled 4
38 11:38:08 GA9081 Amsterdam Cancelled 4
39 11:38:08 KL1017 Amsterdam Cancelled 4
40 11:38:08 MF9651 Amsterdam Cancelled 4
113 11:38:08 9W8916 Amsterdam On time 14:25 4
114 11:38:08 G35524 Amsterdam On time 14:25 4
115 11:38:08 KL1019 Amsterdam On time 14:25 4
116 11:38:08 MF9653 Amsterdam On time 14:25 4
144 11:38:08 AA6505 Amsterdam On time 14:35 5
145 11:38:08 BA435 Amsterdam On time 14:35 5
279 11:38:08 G35530 Amsterdam On time 16:05 4
280 11:38:08 KL1021 Amsterdam On time 16:05 4
281 11:38:08 MF9929 Amsterdam On time 16:05 4
The code:
System.out.println("Enter time: (HH:MM:SS)");
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
try {
Time tme = new Time(sdf.parse(in.nextLine()).getTime());
System.out.println(tme);
while(rs.next()) {
System.out.println(rs.getString(2));
System.out.println("New Time: " + tme);
rs.updateTime(2, tme);
rs.updateRow();
}
}
The problem I'm facing is that the updated time is wrong.
I insert "22:22:22" and it seems that tme
(Time object) recieves the correct time (because System.out.println(tme)
prints "22:22:22") but the results inside the database are wrong.
That's the result AFTER executing the query with tme
='22:22:22':
35 01:52:22 9W8915 Amsterdam Cancelled 4
36 01:52:22 DL9644 Amsterdam Cancelled 4
37 01:52:22 G35516 Amsterdam Cancelled 4
38 01:52:22 GA9081 Amsterdam Cancelled 4
39 01:52:22 KL1017 Amsterdam Cancelled 4
40 01:52:22 MF9651 Amsterdam Cancelled 4
113 01:52:22 9W8916 Amsterdam On time 14:25 4
114 01:52:22 G35524 Amsterdam On time 14:25 4
115 01:52:22 KL1019 Amsterdam On time 14:25 4
116 01:52:22 MF9653 Amsterdam On time 14:25 4
144 01:52:22 AA6505 Amsterdam On time 14:35 5
145 01:52:22 BA435 Amsterdam On time 14:35 5
279 01:52:22 G35530 Amsterdam On time 16:05 4
280 01:52:22 KL1021 Amsterdam On time 16:05 4
281 01:52:22 MF9929 Amsterdam On time 16:05 4
The output from the console:
Enter time: (HH:MM:SS)
22:22:22
22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
11:38:08
New Time: 22:22:22
As you can see, the time in the second column has been updated to "01:52:22" insted of "22:22:22".
I don't understand why the time in 2nd column has changed to 01:52:22 if tme
contains 22:22:22.
Any ideas will be very appreciated!