How to convert String to Date in EL?
Kazuaki Miyauchi <[email protected]> Mon, 19 Aug 2019 12:45:32 +0900
| Newsgroups | gmane.comp.jakarta.taglibs.user |
|---|---|
| Message-ID | <CAFLYOCGFpm-mV5uC7JJRGZGtwrDFuYAfB72qaY-gw5vofb-ShQ@mail.gmail.com> |
I made following JSP.
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<html>
<head>
<title>Insert Date</title>
</head>
<body>
<c:catch var="ex">
<sql:setDataSource dataSource="jdbc/kome" var="kome"/>
<sql:update var="stmt" dataSource="${kome}">
insert into test values(?,?)
<sql:dateParam value="2019-8-19" type="DATE"/>
<sql:param value="Good Day"/>
</sql:update>
</c:catch>
<c:if test="${not empty ex}">
<c:out value="${ex}" />
</c:if>
</body>
</html>
Table was simply made as following.
create table test (when_cause date, how text);
Then, I got following error in tomcat-9.0.22.
org.apache.jasper.JasperException: Unable to convert string
[2019-8-19] to class [java.util.Date] for attribute [value]: [Property
Editor not registered with the PropertyEditorManager]
How to convert String date data to Date type?
After changing as following, it works.
But, it's not easily readable when making complicated sql.
<sql:update var="stmt" dataSource="${kome}">
insert into test values('2019-8-19',?)
<sql:param value="Good Day"/>
</sql:update>
Regards, Kazuaki Miyauchi, Japan