?
Solved

sql:dateParam problem

Posted on 2003-03-02
12
Medium Priority
?
519 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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