Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a postgres DB containing a table with a boolean array for the days of the week (t/f whether the employee has to work on this day or not).

The table is as follows:

CREATE TABLE employee(
        ...,
    weekdays BOOLEAN[7],
        ...
);

In my Java servlet I would like to read and write the array using a boolean[] (primitive type). I have found out that it should work with the java.sql.Array Object.

Inserting does not work with the following:

Connection dbcon = DataSource.checkOut();

preparedStatement pstatement = dbcon.prepareStatement("INSERT INTO employee (weekdays) VALUES (?)");
pstatement.setArray(1, dbcon.createArrayOf("BOOLEAN", castToObjectType( objectToInsert.getWorkingdays() ).toArray() ) );

...

private ArrayList<Boolean> castToObjectType(boolean[] valueArray){
    ArrayList<Boolean> objArray = new ArrayList<Boolean>();

    for (int i = 0; i < valueArray.length; i++) {
        objArray.add( new Boolean(valueArray[i]) );
    }

    return objArray;
}

I'm getting an org.postgresql.util.PSQLException: Unable to find server array type for provided name BOOLEAN exception.

I'm also somehow stuck the way round doing the conversion from java.sql.Array to boolean[]. Ideas, Best practices?

share|improve this question
 
It's not clear from your question - does your code currently work? –  Duncan 57 mins ago
 
no, it does not work –  t7bdh3hdhb 45 mins ago
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.