我的WEB页面是用JAVA的MVC架构的,我的MYSQL数据库表中一个字段PRICE由于特殊需要必须设置成varchar(10)而不能设置成INT,这样当我在WEBINF文件夹里的hql.properties文件写了一个SQL语句qry.merchantbyprice = select mer from Merchant as mer where mer.price > ? and mer.price < ? 时,前台我的代码是
String sql="";
String hql="";
Page page2 = null;
pl.add("minprice");
pl.add("maxprice");
sql="qry.merchantbyprice";
hql = SQLConsts.getInstance().getValue(sql);
ArrayList al = new ArrayList();
al.add("0");
al.add("50");
page2=PageUtil.selectPOs(hql, al ,constPage );
这样结果发现好象后台SQL语句是对price作为STRING进行比较,而不是对它作为INT进行比较,而我如果直接在MYSQL-FRONT后台直接输入select * from tablename where price > 0 and price < 50又是可以的,有哪为高手能指点一下该如何实现吗,对了,我试过al.add(0),结果提示al.add(int)方法不存在。 

解决方案 »

  1.   

    select mer from Merchant as mer where mer.price > ? and mer.price < ?
    的寫法嚴格來說是不好的!MYSQL 應該有將數字字串 cast 為數字的函數!我的意思你的明白!假如cast function 為  castStrToNumFunction(這裡是假設)
    select mer from Merchant as mer where castStrToNumFunction(mer.price) > castStrToNumFunction(mer.price)(?) and (mer.price) < (?)
      

  2.   

    恩,楼上的意思我了解,但是我刚才搜索了一下,别人是说有CAST 和CONVERT都可以转换,但是我放到MYSQL里发现这些都不是保留字。