java enum and postgresql enum

前端 未结 2 604
天命终不由人
天命终不由人 2021-01-19 07:48
CREATE TABLE customers
(
  first_name character varying(15),
  second_name character varying(20),
  login character varying(15) NOT NULL,
  password character varyin         


        
相关标签:
2条回答
  • 2021-01-19 08:03

    I can take no credit for this answer as you have already solved it, but I will explain why it works.

    PostgreSQL provides the answer when it says

    Hint: You will need to rewrite or cast the expression

    The Java code is creating a string literal value that represents the Java enum gendertype type.

    Casting a literal to a PostgreSQL gender type is done by adding a casting suffix to the value ::gender.

    So valid input would be

    'F'::gender
    

    or

    'M'::gender
    

    This works because all PostgreSQL types have a input method that takes a text representation and converts that to the internal form.

    0 讨论(0)
  • 2021-01-19 08:19

    Your solution would have been

    pre_state.setObject(6, gendertype.F.toString(), Types.OTHER);
    
    0 讨论(0)
提交回复
热议问题