在JSP中与数据库相连用的是值连  想起到查询功能,用的是预处理 SQL语句是
select * 
from tblcategory,tblproduce
where tblcategory.category=tblproduce.category and name like '%?%'
这样会报错  为什么阿?? 
这种方式不行 拿什么可以做到模糊查询呢  请哪位高手指导以下阿阿

解决方案 »

  1.   

    Like thisPreparedStatement cmd = cn.prepareStatement("select * 
    from tblcategory,tblproduce
    where tblcategory.category=tblproduce.category and name ?");
    cmd.setString(1,"%m%");
      

  2.   

    select * 
    from tblcategory,tblproduce
    where tblcategory.category=tblproduce.category and name like '%?%'
    1这条sql语句从效率上不是太高.多表关联尽量用inner join 
    2sql中的name字段表达不明确,sql无法知道此name是tblcategory的 还是tblproduce的
    整理后如下:
    select * from tblcategory inner join tblproduce on tblcategory.category=tblproduce.category  where tblcategory.name like '%?%'