Thread: Custom Data Type Mapping JDBC
Hello all,
Let me explain the situation to the best of my knowledge. I am running postgres 8.1, and I read the documentation on CREATE TYPE, this could be extremely usefull for us at the moment. So I went ahead with this little test
CREATE TYPE boolean_date AS(
checked bool,
value date
);
CREATE TABLE answers(
id serial primary key,
answer1 boolean_date NOT NULL,
answer2 boolean_date NOT NULL,
comments text NOT NULL DEFAULT 'NONE'
);
INSERT INTO answers VALUES(default, (true,'02-02-2004'),(false,null),'Hello World');
--query sucessfull
SELECT * FROM answers
id answer1 answer2 comments
-- ------------ ------------ ---------------
1 (t,'02-02-2004) (f,) 'Hello World'
-- All good
SELECT (answer1::boolean_date).checked FROM answers
id checked
-- ------------
1 t
Now the question is, how would I go about inserting, selecting and updating answer1 and answer2 using JDBC?
Could setObject help?
I know I could do a prepared statement like so
INSERT INTO answers(?,(?,?),(?,?),?);
But that will ruin the purpose of creating a custom type for a set of values, wouldn't it?
Thank you for taking the time to read this, if any clarification about the problem is required please mention it.
Best Regards,
Fotis