今天写到这个,很郁闷,用了三种方法:
1:
2
3:
最后实在无语,只能拼串解决问题:
这样最后终于达到模糊匹配查询功能。
还望各位高人告诉鄙人第一种方法为什么不行。在此谢过。
PreparedStatement stat ; Connection conn;
1:
stat = conn.PreparedStatement("select * from book where bookname like '%'?'%'");
编译没有问题,但是就是查询没有结果,很郁闷,现在都还没有搞明白原因。2
:[code="java"]stat = conn.PreparedStatement("select * from book where bookname like %?%"
);[/code]编译错误,直接否决掉。3:
stat = conn.PreparedStatement("select * from book where bookname like '%?%'");
编译无误,但是他将?作为查询参数,不能起到preparedStatement语句的作用。最后实在无语,只能拼串解决问题:
:[code="java"]stat = conn.PreparedStatement("select * from book where bookname like ?");
stat.setString(1,"%"+bookname+"%");
这样最后终于达到模糊匹配查询功能。
还望各位高人告诉鄙人第一种方法为什么不行。在此谢过。