Answer the question
In order to leave comments, you need to log in
Enum what's wrong?
good afternoon everyone have enum
public enum gendertype {
F,
M;
}
<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>
@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);
}
}
Answer the question
In order to leave comments, you need to log in
I don't know java, but where do you even pass the 4th parameter to the request?
The error says that java, using the extended protocol, declares that it transfers data of the varchar type, instead of the gender type. Yes, for the extended protocol these are different things and we will not automatically change the type.
Try like this:VALUES (?,?,?,cast(? as gender))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question