CREATE TABLE customers
(
first_name character varying(15),
second_name character varying(20),
login character varying(15) NOT NULL,
password character varying(15),
email character varying(40),
gender gender,
register_date date,
date_of_birth date,
address character varying(40),
address_number integer,
town character varying(20),
CONSTRAINT login PRIMARY KEY (login)
)
我有这张表,我创建了一个性别枚举,例如:
CREATE TYPE gender AS ENUM ( 'F', 'M',);
我正在尝试使用 PreparedStatement 将来自 eclipse java 的数据插入客户数据,但出现错误,例如 ERROR: column "gender" is of type gender but expression is of type character varying 提示:您将需要重写或强制转换表达式。
我的 Java 代码如下所示:
PreparedStatement pre_state;
public enum gendertype {
F,
M;
}
pre_state = conn.prepareStatement("INSERT INTO"
+ " customers VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
pre_state.set(6, gendertype.F.toString());