
mysql插入单引号字符串
此时将字符串中的单引号" ' "替换成" ' ' "两个单引号即可。
此时应该利用java中的“replace”方法进行替换。此处给出java中的替换代码。
- public static void main(String[] args) throws Exception{
- Server ss=new Server();
- String str="I'm a boy";
- String temp=str.replaceAll("'", "''");
- String sql="insert into test VALUES('"+temp+"');";
- ss.operate(sql, 2);
- System.out.println(temp);
- System.out.println(sql);
- }
此时的输出结果:
- I''m a boy
- insert into test VALUES('I''m a boy');
此时可以正确针对数据库进行操作。
============ 欢迎各位老板打赏~ ===========


与本文相关的文章
- · docker定时任务Mysql脚本
- · docker安装mysql8注意事项
- · .NET8 Mysql SSL error
- · 定时备份docker中的mysql
- · docker-compose通过容器名连接mysql
- · unity3d mysql error: The given key was not present in the dictionary.
- · MySQL 批量修改数据表编码及字符集
- · Your database must use ‘READ-COMMITTED’ as the default isolation level.
- · MySQL-InnoDB存储引擎
- · 将数据从mysql迁移到clickhouse
- · mysql关于索引那些事儿
- · mysql大数据表加字段改名