Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5980741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:50:40+00:00 2026-05-22T21:50:40+00:00

I have a java.sql.Time field in a model that I’m trying to populate from

  • 0

I have a java.sql.Time field in a model that I’m trying to populate from a form submission. Whatever format it’s expecting for those values isn’t the one(s) I want to use, validation always results in “Incorrect value”.

How can I customize the parsing for these values? I thought I’d seen how to do it a while back but I can’t find that info now that I actually need it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:50:40+00:00Added an answer on May 22, 2026 at 9:50 pm

    The magic word was “binding”. What I need to do is create a custom global binder.

    Update: here’s my custom binder that will handle several different time formats:

    import play.data.binding.*;
    
    import org.joda.time.format.*;
    
    import java.lang.annotation.*;
    import java.sql.Time;
    import java.text.ParseException;
    import java.util.regex.*;
    
    @Global
    public class SqlTimeBinder implements TypeBinder<Time> {
        private static final Pattern TWELVE_HOUR = Pattern.compile("^\\d{1,2}:\\d{2}[ap][m]?$", Pattern.CASE_INSENSITIVE);
        private static final Pattern TWELVE_HOUR_SHORT = Pattern.compile("^\\d{1,2}[ap][m]?$", Pattern.CASE_INSENSITIVE);
        private static final Pattern TWENTYFOUR_HOUR = Pattern.compile("^\\d{1,2}:\\d{2}$");
    
        private DateTimeFormatter twelve_hour = DateTimeFormat.forPattern("h:ma");
        private DateTimeFormatter twelve_hour_no_minutes = DateTimeFormat.forPattern("ha");
        private DateTimeFormatter twenty_four_hour = DateTimeFormat.forPattern("H:m");
    
        public Object bind(String name, Annotation[] annotations, String value, Class clazz, java.lang.reflect.Type genericType) {
            if (value == null || value.length() == 0) {
                return null;
            }
    
            Matcher m = TWELVE_HOUR.matcher(value);
            if (m.matches()) {
                return new java.sql.Time(twelve_hour.parseDateTime(value).getMillis());
            }
            m = TWELVE_HOUR_SHORT.matcher(value);
            if (m.matches()) {
                return new java.sql.Time(twelve_hour_no_minutes.parseDateTime(value).getMillis());
            }
    
            m = TWENTYFOUR_HOUR.matcher(value);
            if (m.matches()) {
                return new java.sql.Time(twenty_four_hour.parseDateTime(value).getMillis());
            }
    
            throw new IllegalArgumentException("Invalid time");
        }
    }
    

    I put this in app/lib which works fine, I’m still debating whether this the “right” place for it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Java code that connects to an SQL server DB but I cannot
I have some Java objects that I want to transform to XML. Some of
I have an extensive DATE-TIME conversion class, but i came across a scenario that
I am writing a Java code generator. I have an immutable Map that contains
Lets say i have the following bit of code import java.sql.Connection; import java.sql.DriverManager; import
I'm trying to put a user provided date into an SQL database, and I
I am using PreparedStatement to query my table. Unfortunately, I have not been able
I would like to have an easy way to run queries like the following
I'm Using Oracle 11g and JPA 2.0 (hibernate in JBoss 6.0.0). I need to
I am stress testing my application using JMeter my app is made an Asp.net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.