Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to insert date into oracle database

387981May 27 2003
Hi, there,

I want to insert date information to oracle database in a jsp page using JSTL. but always got wrong message:

javax.servlet.jsp.JspException:
INSERT INTO DATE_TEST
(date_default,date_short,date_medium)
values(?,?,?)
: Invalid column type
...

I don't know how to convert java date type to oracle date type or vice versa. the following is the source code(all the fields of DATE_DEFAULT,DATE_SHORT,DATE_MEDIUM are oracle date type. and even I want to insert d instead d1, I got the same wrong message)

<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%
Calendar now;
Calendar rightNow = Calendar.getInstance();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>
Hello World
</title>
</head>
<body>
<h2>
The current time is:
</h2>
<p>
<%= new java.util.Date() %></p>

<%
java.util.Date d=new java.util.Date();
java.sql.Date d1=new java.sql.Date(d.getYear(),d.getMonth(),d.getDate());
out.print(d1.toString());
%>
<sql:update>
INSERT INTO DATE_TEST
(DATE_DEFAULT,DATE_SHORT,DATE_MEDIUM)
VALUES(?,?,?)
<sql:dateParam value="${d}" type="date" />
<sql:dateParam value="${d}" type="date" />
<sql:dateParam value="${d}" type="date" />
</sql:update>
</body>
</html>

thank you very much for the great help!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 24 2003
Added on May 27 2003
0 comments
341 views