This question already has an answer here:
Use of LIKE clause in sql prepared statement, spring, SimpleJDBCTemplate
                                
                                    (1个答案)
                                
                        
                                3年前关闭。
            
                    
ps=con.prepareStatement("select * from REGISTER inner join ORGAN on REGISTER.PATIENTID=ORGAN.PATIENTID where ORGAN.ORGAN LIKE ?");
ps.setString(1,"'%"+o.getOrgan()+"%'");


我在SQL Developer中执行了正常的查询,但是在DAO类中,它不返回任何结果集。

最佳答案

使用

ps.setString(1, "%" + o.getOrgan() + "%");


请注意没有引号。

09-30 00:38