gpt4 book ai didi

java - 特殊字符未保存在数据库中

转载 作者:行者123 更新时间:2023-11-29 07:27:30 25 4
gpt4 key购买 nike

我正在插入带有特殊字符的字符串,但显示问号(“?”)

代码-

  String mainquery = "INSERT INTO thread_pitch_gauge ( nominal_value, ob1, ob2) VALUES(?,?,?)";
String n1 = 56°± 116’;
String n2 = 56° 16’ 44’’;
String n3 = 56° 16’ 45’’;
ps = (PreparedStatement) connection.prepareStatement(mainquery);
ps.setInt(1, n1);
ps.setString(2, n2);
ps.setString(3, n3);
ps.execute();
ps.close();
in database value showing like
nominal_value=56°± 116’
ob1=56° 16’ 44’’
ob2=56° 16? 45?;

我的数据库表所有字段类型都是varchar(50)我在java中遇到这个问题数据库是mysql请帮我提前致谢

最佳答案

在插入数据库之前需要转义特殊字符

There are a number of special characters that needs to be escaped (protected), if you want to include them in a character string. Here are some basic character escaping rules:

以下是如何包含特殊字符的一些示例:

SELECT 'It''s Sunday!' FROM DUAL;
It's Sunday!

SELECT 'Allo, C\'est moi.' FROM DUAL;
Allo, C'est moi.

SELECT 'Mon\tTue\tWed\tThu\tFri' FROM DUAL;
Mon Tue Wed Thu Fri

http://dba.fyicenter.com/faq/mysql/Escape-Special-Character.html

关于java - 特殊字符未保存在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34036919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com