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

  • Home
  • SEARCH
  • 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 7446687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:23:04+00:00 2026-05-29T12:23:04+00:00

I have a table with a time without time zone data type in a

  • 0

I have a table with a “time without time zone” data type in a postgres database and I’m getting a syntax error when trying to insert using prepared statements. I’ve tried creating a new java.sql.Time object rather than using inputs from a web page and I am still getting the same error. What am I doing wrong?

Error:

org.postgresql.util.PSQLException: ERROR: invalid input syntax for type time: "1970-01-01 +01:00:00"

Table:

                                     Table "public.reservation"
   Column   |          Type          |                          Modifiers
------------+------------------------+--------------------------------------------------------------
 res_id     | integer                | not null default nextval('reservation_res_id_seq'::regclass)
 cust_id    | character varying(50)  | not null
 date       | date                   | not null
 time       | time without time zone | not null
 num_people | integer                | not null
Indexes:
    "reservation_pkey" PRIMARY KEY, btree (res_id)
Foreign-key constraints:
    "reservation_cust_id_fkey" FOREIGN KEY (cust_id) REFERENCES customer(cust_id)
Referenced by:
    TABLE "reservation_table" CONSTRAINT "reservation_table_res_id_fkey" FOREIGN KEY (res_id) REFERENCES reservation(res_id)

Reservation Java:

 public static boolean createReservation(String custID, Date date, Time time, int numPeople) throws ServletException {

    //TODO add checking
    //TODO need to add determing table and if reservation time is free

    boolean succeeded = false;

    //checks if reservation is possible to be booked
    if(checkReservationPossible()){

        //convet date to correct format for database
        //SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy/MM/dd");
        //String formattedDate = dateFormatter.format(date);

        //convert time to correct format for database
        //SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm");
        //String formattedTime = timeFormatter.format(time);

        DatabaseAccess db = new DatabaseAccess();
        String sql = "INSERT INTO reservation (cust_id, date, time, num_people)"
                + "VALUES (?,?,?,?)";

        LinkedList<Object> params = new LinkedList<Object>();
        params.add(custID);
        params.add(date);
        params.add(time);
        params.add(numPeople);

        succeeded = db.runUpdateQuery(sql,params);

        db.close();
    }

    return succeeded;
}

DB Access Java:

public boolean runUpdateQuery(String sql, LinkedList<Object> params) throws ServletException
{
    // Using try {...} catch {...} for error control
    try{
        // Create a statement variable to be used for the sql query
        //Statement statement = this.connection.createStatement();

        // Perform the update

        PreparedStatement pst = this.connection.prepareStatement(sql);

        Iterator iter = params.iterator();

        for(int i = 1;iter.hasNext(); i++){
            Object curr = iter.next();
            //TODO may need to add more for different types
            if(curr instanceof String){
                pst.setString(i, curr.toString());
            }else if (curr instanceof Integer){
                pst.setInt(i, (Integer)curr);
            }else if (curr instanceof java.util.Date){
                //convert to sql date
                java.util.Date tempDate = (java.util.Date)curr;
                java.sql.Date sqlDate = new java.sql.Date(tempDate.getTime());
                pst.setDate(i, sqlDate);
            }else if (curr instanceof Time){
                pst.setTime(i, Time.valueOf("11:30:00"));
            }
        }

        int numRows = pst.executeUpdate();

        pst.close();

        if(numRows > 0){
            return true;
        }else{
            return false;
        }
    } catch (SQLException e){
        // Deal with the error if it happens
        throw new ServletException(String.format("Error: Problem running query... "), e);
    }
}
  • 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-29T12:23:05+00:00Added an answer on May 29, 2026 at 12:23 pm

    You don’t need all that checking. I recommend you change you code to simply this:

    for (int i = 1; iter.hasNext(); i++) {
        Object curr = iter.next();    
        pst.setObject(i, curr);
    }
    

    JDBC knows what to do with all the various usual java types – no need to convert.

    The only time you need to check the type is if you want to use some custom class and you want to get some JDBC compliant type from it. This is not the case here.

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

Sidebar

Related Questions

I have a table with a timestamp without time zone column (data entered is
I happen to have tables with timestamp without time zone column in my database.
I have a table of time-series data of which I need to find all
I have a database table full of time points and experimental values at those
I am trying to select data from a table, using a like on date
I have the following table of TIME datatypes clarification: I am representing hours/mins/seconds of
I have a table populated with time stamped rows inserted at (essentially) random point
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have table with a unique auto-incremental primary key. Over time, entries may be
I have a table containing reports and the date/time they were created. I'd like

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.