Horace919
Horace919
2017-04-25 01:06

关于java和mysql的查询问题。怎么弄一个上下区间的数字查询,求大神指教

100
  • java
  • mysql

想弄成这样图片说明
但是价格和面积两项的检索有问题
这是我的jsp代码




户型:







地址:







价格:


onkeyup="value=value.replace(/[^\d]/g,'') "
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
---
onkeyup="value=value.replace(/[^\d]/g,'') "
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>




面积:


onkeyup="value=value.replace(/[^\d]/g,'') "
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
---
onkeyup="value=value.replace(/[^\d]/g,'') "
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>


这里是方法的代码
public String chuzuRes()
{
List chuzuList=new ArrayList();
HttpServletRequest request=ServletActionContext.getRequest();
String jiage1=request.getParameter("jiage1").trim();
String jiage2=request.getParameter("jiage2").trim();
String mianji1=request.getParameter("mianji1").trim();
String mianji2=request.getParameter("mianji2").trim();
    if(jiage1.equals(""))
    {
        jiage1="0";
    }
    if(jiage2.equals(""))
    {
        jiage2="888888888";
    }
    if(mianji1.equals(""))
    {
        mianji1="0";
    }
    if(mianji2.equals(""))
    {
        mianji2="888888888";
    }


    StringBuffer sql=new StringBuffer("from TChuzu where huxing like '%"+huxing.trim()+"%'"+" and dizhi like '%"+dizhi.trim()+"%'");
    List chuzuList1=chuzuDAO.getHibernateTemplate().find(sql.toString());
    for(int i=0;i<chuzuList1.size();i++)
    {
        TChuzu chuzu=(TChuzu)chuzuList1.get(i);
        Double jiage=Double.parseDouble(chuzu.getJiage());
        Double mianji=Double.parseDouble(chuzu.getMianji());
        System.out.println(mianji+"YY");

        if(jiage >=Double.parseDouble(jiage1) && jiage <=Double.parseDouble(jiage2) && mianji >=Double.parseDouble(mianji1) && mianji <=Double.parseDouble(mianji2))
        {
            chuzuList.add(chuzu);
        }
    }
    request.setAttribute("chuzuList", chuzuList);
    return ActionSupport.SUCCESS;
}


现在是上面的两项正常,下面两个报错。
求大神给看看怎么改合适
报错:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NumberFormatException: empty String
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
root cause

java.lang.NumberFormatException: empty String
sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
java.lang.Double.parseDouble(Double.java:510)
com.action.chuzuAction.chuzuRes(chuzuAction.java:168)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

7条回答