java查询mysql是关键字带有单引号的解决方式

(1) 最近发现,java代码访问mysql5.5查询时,假如关键字带有'是不能查询的,我又不是开发java的,一顿百度,最后的方案如下。
    
    不能正常查找的查询语句:select category ,ncRNA ,species,cancer,gene_cell,expression,effect,COUNT(1) from cancerdata where cancer ='Wilms' tumor' GROUP BY category ,ncRNA ,species,cancer,gene_cell,expression,effect
(2) java代码对关键字进行处理如下,单引号换成双引号。
     currentName = currentName.replaceAll("'", "''");
     
(3) 修改后的查询语句。
    select category ,ncRNA ,species,cancer,gene_cell,expression,effect,COUNT(1) from cancerdata where cancer ='Wilms'' tumor' GROUP BY category ,ncRNA ,species,cancer,gene_cell,expression,effect
(4) 这样就可以查询到结果了。

猜你喜欢

转载自blog.csdn.net/qq_14874791/article/details/106634413