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 7920543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:15:32+00:00 2026-06-03T16:15:32+00:00

How do I pass an array of timestamps to the Postgres function using Java

  • 0

How do I pass an array of timestamps to the Postgres function using Java and JDBC?

Here’s the signature of the function:

CREATE OR REPLACE FUNCTION getlistcount(_id integer, _subs text, _download_array timestamp without time zone[], _filter integer, _fault text) RETURNS refcursor AS...

Here is the Java code that creates the array:

GregorianCalendar[] dataDownloads = 
        downloadTimes.toArray(new GregorianCalendar[downloadTimes.size()]);

Array sqlArray = conn.createArrayOf("timestamp", dataDownloads);
cstmt.setArray(4, sqlArray);

The downloadTimes are List passed into the Java function.

One hint: we need to concatenate the time with the date, according to the Postgres documentation.

  • 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-06-03T16:15:34+00:00Added an answer on June 3, 2026 at 4:15 pm

    I found an answer on StackOverflow that is similar, but uses the PreparedStatement rather than the JDBC notation.

    //Get timezone from first entry, assuming all same timezone
    if(!downloadTimes.isEmpty()) {
        cal.setTimeZone(downloadTimes.get(0).getTimeZone());
    }
    
    //Create an array of timestamps
    java.sql.Timestamp [] array = new java.sql.Timestamp [downloadTimes.size()];
    
    for(int i=0; i < array.length; i++) {
        array[i] = new java.sql.Timestamp(downloadTimes.get(i).getTimeInMillis());
    } 
    
    //pass the array to JDBC call
    //conn is the connection, and cstmt is the CallableStatement
    Array sqlArray = conn.createArrayOf("timestamp", array);
    cstmt.setArray(4, sqlArray);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this post pass array to method Java on how to pass
I want to pass an array of arbitrary struct pointers and a comparison function
How do I pass an array key to a function to pull up the
How do you pass Array dimensions along with the Array in java? I invision
Possible Duplicate: PHP function with unlimited number of parameters How to pass array as
In order to pass array variables via my curl script, I am using serialize
How can I pass an array by reference in Java? For instance I need
I need to pass an array to a function in C# where the array
im trying to pass an array as a string $(document).ready(function(){ var args = {};
I tried to pass Array of javascript classes in $.post function, but in controller

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.