Allow bad time error format in java?

I am working with java to retrieve the values ​​of a time column in a table in mysql.

The code below shows the request I am sending.

String query="select id,time from table where Hour(time)<=32 ";
ResultSet res = stmt.executeQuery(query);
while (res.next()) {
  String id = res.getString(1); 
  Time tc = res.getTime("time");
  System.out.println(tc);
}

time values ​​can be negative (-56: 00: 00, which means that we have exceeded a certain delay. the problem is what I get: java.sql.SQLException: java.sql.SQLException: Bad formatfor Time '-05: 48: 49' in column 2.

thank you for your help.

+3
source share
4 answers

As mentioned in the previous question , you need to save and process it as seconds, which are stored as a signed integer .

. varchar/string , Andreas_D, . - , . PreparedStatement#setInt(), ResultSet#getInt(), .

+1

, ResultSet, , String String Date ( ):

  String query="select * from table where Hour(time)<=32 ";
  ResultSet res = stmt.executeQuery(query);
  while (res.next()) {
    String id = res.getString(1); 
    Time tc = convertToDate(res.getString("time"));
    System.out.println(tc);
  }

  // ....

}

private Time convertToDate(String s) {
  // implement magic here

}
+2

, . , . :

select id,concat(time,'') from table where Hour(time)<=32

.

+1

, .

When you run directcly, the query [select * from the table where Hour (time) <= 32] does not return you an error? I assume the error is in the where [Hour (time) <= 32] clause

The result set has no information about the where clause. It just returns all the columns.

You need to check the return of the columns to see if you are returning some kind of weird type.

0
source

Source: https://habr.com/ru/post/1759882/


All Articles