?
Solved

sql:dateParam problem

Posted on 2003-03-02
12
Medium Priority
?
523 Views
Last Modified: 2012-05-04
Hi,
I am trying to take a parameter that is passed from an earlier page:

<jsp:forward page="pnRequestNewResult.jsp">
     <jsp:param name="dateAdd" value="<%= now.toString() %>"/>
</jsp:forward>

and do a query on a MySQL database on the new page:

<%
//     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     DateFormat df = new DateFormat();
%>

<sql:query var="rs" scope="request" dataSource="${conn}">
     SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
     <sql:param value="${param.txtNameLogin}" />
     <sql:dateParam value="<% df.parse(${request.getParameter("dateAdd")}); %>" type="timestamp" />
</sql:query>

I'm getting an error:

org.apache.jasper.JasperException: /pnRequestNewResult.jsp(20,66) equal symbol expected

which I assume means I'm not using the correct syntax to provide the sql:dateParam value.  This worked when I wasn't using WHERE in the SELECT (no parameters).

All the examples I can find just use a request parameter directly.  Need help with how to format this.

Thanks,
Eric
PS I am assuming that the position (20,66) in the error message is zero based, that is the upper left corner of the jsp page is row zero, column zero?
0
Comment
Question by:EricE
  • 6
  • 5
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8055203
Should be something like:

<sql:query var="rs" scope="request" dataSource="${conn}">
    SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
    <sql:param value="${param.txtNameLogin}" />
    <sql:dateParam value="<%= df.parse(request.getParameter("dateAdd")) %>" type="timestamp" />
</sql:query>


Though I'm not sure what you intend with:
${conn}
${param.txtNameLogin}

0
 
LVL 92

Expert Comment

by:objects
ID: 8055206
> DateFormat df = new DateFormat();

That won't work either as DateFormat is an abstract class.
Use one of it's static methods, or SimpleDateFormat instead.
0
 

Author Comment

by:EricE
ID: 8055388
Hi,
Made the change and now have another error message:

org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 55 in the jsp file: /pnRequestNewResult.jsp
Generated servlet error:
    [javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\accuray\pnRequestNewResult_jsp.java:104: cannot resolve symbol
symbol  : method setValue (java.util.Date)
location: class org.apache.taglibs.standard.tag.el.sql.DateParamTag
            _jspx_th_sql_dateParam_0.setValue( sdf.parse(request.getParameter("dateAdd")) );
                                    ^
1 error

Here is the code, only changed to SimpleDateFormat and the <sql:dateParam statement.

<%
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//     DateFormat df = new DateFormat();
%>

<sql:query var="rs" scope="request" dataSource="${conn}">
     SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
     <sql:param value="${param.txtNameLogin}" />
     <sql:dateParam value="<%= sdf.parse(request.getParameter("dateAdd")) %>" type="timestamp" />
</sql:query>

Is "yyyy-MM-dd HH:mm:ss" necessary when converting from a string to a Date?  I got the same error with and without it.

Thanks,
Eric
PS ${conn} was set up as the datasource in some earlier code.  param.txtNameLogin is the name of a text input field on the data entry page
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:EricE
ID: 8055395
Hi,
Need to clarify the error message since the caret might not be pointing to the right spot.  It is pointing at the period between _jspx_th_sql_dateParam_0 and setValue(sdf...).

Eric
0
 
LVL 92

Expert Comment

by:objects
ID: 8055606

Try:

<sql:dateParam value="<%= new java.sql.Date(sdf.parse(request.getParameter("dateAdd")).getTime()) %>" type="timestamp" />
0
 

Author Comment

by:EricE
ID: 8055808
Hi,
Looks like the same error message:

An error occurred at line: 55 in the jsp file: /pnRequestNewResult.jsp
Generated servlet error:
    [javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\accuray\pnRequestNewResult_jsp.java:104: cannot resolve symbol
symbol  : method setValue (java.sql.Date)
location: class org.apache.taglibs.standard.tag.el.sql.DateParamTag
            _jspx_th_sql_dateParam_0.setValue( new java.sql.Date(sdf.parse(request.getParameter("dateAdd")).getTime()) );
                                    ^
1 error

Code is:

<sql:query var="rs" scope="request" dataSource="${conn}">
     SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
     <sql:param value="${param.txtNameLogin}" />
     <sql:dateParam value="<%= new java.sql.Date(sdf.parse(request.getParameter("dateAdd")).getTime()) %>" type="timestamp" />
</sql:query>

I cleared out the work subdirectory and restarted Tomcat to make sure it wasn't using the cached files.

Thanks,
Eric
0
 
LVL 92

Expert Comment

by:objects
ID: 8055903
try this:

<fmt:parseDate value="${param.dateAdd}" var="parsedAddDate"
  pattern="yyyy-MM-dd" />

<sql:query var="rs" scope="request" dataSource="${conn}">
    SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
    <sql:param value="${param.txtNameLogin}" />
    <sql:dateParam value="${parsedAddDate}" type="timestamp" />
</sql:query>



0
 
LVL 92

Expert Comment

by:objects
ID: 8055905
here's an example that may help you:
http://thejspbook.com/jspSource/examples/ch11/store.jsp
0
 

Author Comment

by:EricE
ID: 8062703
Hi,
Seem to be stuck in an infinite loop...  When I made the change you suggested I get an error:

org.apache.jasper.JasperException: In <parseDate>, value attribute can not be parsed: "Mon Mar 03 21:36:41 GMT-08:00 2003"

So I go back to the page that stuffs the parameter with:

<jsp:forward page="pnRequestNewResult.jsp">``
     <jsp:param name="dateAdd" value="${parsedAddDate}"/>
</jsp:forward>

and try to use fmt:parseDate to put the string date in a simpiler format.  I was able to do that according to:

<% out.println(sdf.format(fmtDate)); %>

but I still end up trying to put Java code into a value statement, in this case in the fmt:parseDate:

<fmt:parseDate value=" ${<% sdf.format(fmtDate)); %>} " var="parsedAddDate" pattern="yyyy-MM-dd HH:mm:ss" /> (one of my failed attempts)

so I can pass it to jsp:forward.  The fundamental problem seems to be how do you pass a variable you have defined in regular Java code into the parameter value of a taglib??

Gotta crash now, getting old...  Appreciate any futher thoughts.

Thanks,
Eric
PS I have the book and have that page open in Opera, unfortunately it doesn't get any more complex than the examples at Sun, just uses request parameters.
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 8062723
> Seem to be stuck in an infinite loop

My fault sorry, I misunderstood initially what you were doing :(

What you want to do is format the arg you are passing as required:

<%
   SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd");
%>

<jsp:forward page="pnRequestNewResult.jsp">
    <jsp:param name="dateAdd" value="<%= sdf.format(now) %>"/>
</jsp:forward>



0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8064884
I would suggest you to user request scope bean to pass your date, in forwarding page:

<%request.setAttribute( "dateAdd", now );%>
<jsp:forward page="pnRequestNewResult.jsp" />

or if your prefer tags:

<jsp:useBean id="dateAdd" class="java.util.Date", scope="request" />
<jsp:forward page="pnRequestNewResult.jsp" />

in pnRequestNewResult.jsp:

<sql:query var="rs" scope="request" dataSource="${conn}">
    SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
    <sql:param value="${param.txtNameLogin}" />
    <sql:dateParam value="${dateAdd}" type="timestamp" />
</sql:query>
0
 

Author Comment

by:EricE
ID: 8069784
Hallelujah,
I'd swear I tried that syntax for passing in the value to the forward tag but I was flailing around pretty badly.

Thanks for the alternative Kenneth, I've copied it to comments on the page and will remember for future use.

Thanks,
Eric
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a few different ways to preview your site before DNS resolves it to your (mt) Media Temple server.  The Plesk platform makes it easy.  See the following guide to learn how.
Welcome back to our beginners guide of the popular Unix tool, cron. If you missed part one where we introduced this tool, the link is below. We left off learning how to build a simple script to schedule automatic back ups. Now, we’ll learn how to se…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question