добрый день всем есть enum
public enum gendertype {
F,
M;
}
И поля в базе данных gender c типом gender
помогите разобраться я заполняю форму
<div class="w3-card-4">
<div class="w3-container w3-center w3-green">
<h2>Add user</h2>
</div>
<form method="post" class="w3-selection w3-light-grey w3-padding">
<label for="first-name">Имя:
<input type="text" id="first-name" name="first-name" class="w3-input w3-animate-input w3-border w3-round-large" style="width: 30%"><br />
</label><br />
</label>
<label for="last-name">Фамилия:
<input type="text" id="last-name" name="last-name" class="w3-input w3-animate-input w3-border w3-round-large" style="width: 30%"><br />
</label><br />
<label for="birthDate">Дата рождения
<input class="input-field" type="text" id="birthDate" name="birthDate">
</label>
<select name="gender">
<option value="F">жен.</option>
<option value="M">муж.</option>
</select>
<button type="submit" class="w3-btn w3-green w3-round-large w3-margin-bottom">Submit</button>
</form>
</div>
и есть servlet
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String firsName = req.getParameter("first-name");
String lastName = req.getParameter("last-name");
LocalDate birthDate = LocalDate.parse(req.getParameter("birthDate"));
String genderUser = req.getParameter("gender");
try {
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO data_user(firs_name, last_name, birth_date ,gender) VALUES (?,?,?,?)");
preparedStatement.setString(1, firsName);
preparedStatement.setString(2, lastName);
preparedStatement.setDate(3, java.sql.Date.valueOf(birthDate));
preparedStatement.execute();
}
catch(SQLException e) {
throw new IllegalStateException(e);
}
}
Как через preparedStatement используя enum добавить пользователя указав его пол получаю следующую ошибку
java.lang.IllegalStateException: org.postgresql.util.PSQLException: ERROR: column "gender" is of type gender but expression is of type character varying
Hint: You will need to rewrite or cast the expression.