Matt Williams
Matt Williams

Reputation: 79

Adding a variable to end of a mysql query in jsp?

Im trying to add a variable to the end of a sql query in the following way:

<sql:query var="result" sql="SELECT * FROM Customer WHERE customer_number = <% $x %> />

but its not inputing the variable into the sql query.

What am i doing wrong?

Thanks

Matt

Upvotes: 0

Views: 760

Answers (2)

Sap
Sap

Reputation: 5301

Check out the very first example in this link

http://docs.oracle.com/javaee/1.4/tutorial/doc/JSTL7.html

I think you have gotten the syntax wrong. It goes like

<c:set var="bid" value="${param.Add}"/>
<sql:query var="books" >
  select * from PUBLIC.books where id = ?
  <sql:param value="${bid}" />
</sql:query> 

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240908

if x is the variable set somewhere in request/session/applicationcontext/pagecontext the following will work

<sql:query var="result" sql="SELECT * FROM Customer WHERE customer_number = $x />

Upvotes: 1

Related Questions