Search Results

Search found 1 results on 1 pages for 'mcgin'.

Page 1/1 | 1 

  • Using a PreparedStatement to persist an array of Java Enums to an array of Postgres Enums

    - by McGin
    I have a Java Enum: public enum Equipment { Hood, Blinkers, ToungTie, CheekPieces, Visor, EyeShield, None;} and a corresponding Postgres enum: CREATE TYPE equipment AS ENUM ('Hood', 'Blinkers', 'ToungTie', 'CheekPieces', 'Visor', 'EyeShield', 'None'); Within my database I have a table which has a column containing an array of "equipment" items: CREATE TABLE "Entry" ( id bigint NOT NULL DEFAULT nextval('seq'::regclass), "date" character(10) NOT NULL, equipment equipment[] ); And finally when I am running my application I have an array of the "Equipment" enums which I want to persist to the database using a Prepared Statement, and for the life of me I can't figure out how to do it. StringBuffer sb = new StringBuffer("insert into \"Entry\" "); sb.append("( \"date\", \"equipment \" )"); sb.append(" values ( ?, ? )"); PreparedStatement ps = db.prepareStatement(sb.toString()); ps.setString("2010-10-10"); ps.set???????????

    Read the article

1