如何逃避“ '“在SQL中 [英] How to escape " ' " in sql

查看:130
本文介绍了如何逃避“ '“在SQL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我正在搜索数据库中的名字组合。我传递的组合如下

Hi I am searching for a name combination in database. I am passing the combination as follows

"firstName='" + firstName + "'", "middleName='" + middleName + "'", "lastName='" + lastName + "'"

但问题出现在名称中有一些',我该如何纠正它?例如:Johns'或Jerry's等导致异常

This works fine. But the problem comes where there are some " ' " in names how can i rectify it? eg: Johns' or Jerry's etc causes exception

推荐答案

ps.executeUpdate("INSERT INTO tb_name values(?,?) WHERE id=?");
ps.setString(1,firstName);
ps.setString(2,middleName);
ps.setInt(3,id);
ps.execute();

这篇关于如何逃避“ '“在SQL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆