NullPointerException
NullPointerException

Reputation: 37731

How to parse from SQL Time (String) to java.sql.Time?

i have a database with a Time field. When i get the fields with a php, i receive the Time field as a String, by JSON.

The string i recive is like this: 08:00:00

ok, all work's fine here, but i need to have that String in java.sql.Time format.

There is a easy way to do it?

code:

String hour1=retrieveHourFromPHPSqlConnection();
Time a=hour1;

how to transform hour1 into Time?

thanks

Upvotes: 7

Views: 14814

Answers (1)

LaGrandMere
LaGrandMere

Reputation: 10379

From Javadoc I suggest you to use this :

java.sql.Time myTime = java.sql.Time.valueOf(hour1);

Takes a String in hh:mm:ss format and gives you a java.sql.Time object.

It's valid at least from Java 1.4.2 up to Java 7.

Upvotes: 15

Related Questions