Name and version of the database you are using:MySQL 5.0
I have a problem when trying the following: I want to search with 2 drop down boxes and a submit button. Here's the code and do not be scarry of it's length because for you it may be very simple :
Code:
public static List<Car> getAllCars(Session hibSession, Integer upprice, Integer downprice) {
Query query = hibSession.createQuery ("from Car where price between (upprice = :upprice) and (downprice = :downprice)");
query.setInteger("upprice", upprice);
query.setInteger("downprice", downprice);
return (List<Car>) query.list();
}
And this is the Servlet:
Code:
public class Search extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uppr = request.getParameter("upprice");
Integer upprice = Integer.parseInt(uppr);
String downpr = request.getParameter("downprice");
Integer downprice = Integer.parseInt(downpr);
Session hibSession = HibernateUtils.startSession();
List<Car> price = AccessCars.getAllCars(hibSession, upprice, downprice);
hibSession.flush();
hibSession.close();
HttpSession session = request.getSession();
session.setAttribute("price", price);
response.sendRedirect("Search.jsp");
}
}
and this is the Search.jsp where the results should be //this is only a part of it:
<table border="1">
<tr>
<td>Brand</td>
<td>Model</td>
<td>Color</td>
<td>Engine</td>
<td>Price</td>
</tr>
<c:forEach var="car" items="${price}">
<tr>
<td><c:out value="${car.marka}"></c:out></td>
<td><c:out value="${car.model}"></c:out></td>
<td><c:out value="${car.color}" ></c:out></td>
<td><c:out value="${car.engine}"></c:out></td>
<td><c:out value="${car.price}" ></c:out></td>
</tr>
</c:forEach>
</table>
Here is the error:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: = near line 1, column 48 [from entities.Car where price between (upprice = :upprice) and (downprice = :downprice)]
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
access.AccessCars.getAllCars(AccessCars.java:12)
servlets.Search.doGet(Search.java:23)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
<AST>:1:48: unexpected AST node: =
org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4114)
org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3781)
org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1758)
org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)