• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP INSERT statement  RSS feed

 
p guha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, I am trying to INSERT data in to database. GOT following error.
The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.ArrayIndexOutOfBoundsException
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(JdbcOdbcPreparedStatement.java:1027)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setTimestamp(JdbcOdbcPreparedStatement.java:910)
at com.ora.jsp.sql.SQLCommandBean.setValues(SQLCommandBean.java:197)......
my code:==================================
<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="/orataglib" prefix="ora" %>
<ora:useDataSource id="example"
className="sun.jdbc.odbc.JdbcOdbcDriver"
url="jdbc dbc:example" />
<%--
See if the employee is already defined. If not, insert the
info, else update it.
--%>
<ora:sqlQuery id="empDbInfo" dataSource="example">
SELECT * FROM Customer1
WHERE userName = ?
<ora:sqlStringValue param="userName" />
</ora:sqlQuery>
<% if (empDbInfo.size() == 0) { %>
<ora:sqlUpdate dataSource="example">
INSERT INTO Customer1
(userName,password,firstName,lastName,street,
city,state,zip,phone,email)
VALUES(?,?,?,?,?,?,?,?,?,?)
<ora:sqlStringValue param="userName" />
<ora:sqlStringValue param="passWord" />
<ora:sqlStringValue param="firstName" />
<ora:sqlStringValue param="lastName" />
<ora:sqlStringValue param="street" />
<ora:sqlStringValue param="city"/>
<ora:sqlStringValue param="state"/>
<ora:sqlStringValue param="zip"/>
<ora:sqlStringValue param="phone"/>
<ora:sqlStringValue param="email" />
<ora:sqlTimestampValue value="<%= new java.util.Date() %>" />
</ora:sqlUpdate>
<% } else { %>
<ora:sqlUpdate dataSource="example">
UPDATE Employee
SET Password = ?,
FirstName = ?,
LastName = ?,
Dept = ?,
EmpDate = ?,
EmailAddr = ?,
ModDate = ?
WHERE UserName = ?
<ora:sqlStringValue param="password" />
<ora:sqlStringValue param="firstName" />
<ora:sqlStringValue param="lastName" />
<ora:sqlStringValue param="dept" />
<ora:sqlDateValue param="empDate" pattern="yyyy-MM-dd" />
<ora:sqlStringValue param="emailAddr" />
<ora:sqlTimestampValue value="<%= new java.util.Date() %>" />
<ora:sqlStringValue param="userName" />
</ora:sqlUpdate>
<% } %>
<%-- Get the new or updated data from the database --%>
<ora:sqlQuery id="newEmpDbInfo" dataSource="example" scope="session">
SELECT * FROM Customer1
WHERE userName = ?
<ora:sqlStringValue param="userName" />
</ora:sqlQuery>
<%-- Redirect to the confirmation page --%><ora:redirect page="confirmation.jsp" />

===================end of code
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<ora:sqlTimestampValue value="<%= new java.util.Date() %>" />
is the problem.
Try new java.sql.Date()
java.util.Date().toString() formats in a way that Oracle cannot understand.
Even better, you might want to pass the Date object directly instead of putting a string inside a scriptlet, then having Oracle convert the String back to a date. (I don't know how to do that with this tag library though. It may not be possible if the tag library only accepts String objects).
When passing the timestamp as a String (inside a <%= ... %> , you run the risk of sending the date formatted in a different Locale than how the database is set up to receive the date. You might want to just use a string formatted as 'DD-MON-YYYY'.
 
p guha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got following error when i change to new java.sql.Date()
=====
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 35 in the jsp file: /store.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0\work\Standalone\localhost\BankApp\store$jsp.java:455: No constructor matching Date() found in class java.sql.Date.
_jspx_th_ora_sqlTimestampValue_0.setValue( new java.sql.Date() );
 
p guha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i hard coded the date 02/02/2002 will give me following error=======
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to convert string '02/02/2001' to class java.util.Date for attribute value: java.lang.IllegalArgumentException: Property Editor not registered with the PropertyEditorManager
at org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromPropertyEditorManager(JspRuntimeLibrary.java:749)
at org.apache.jsp.store$jsp._jspService(store$jsp.java:455)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!