Reputation: 21
I am inserting string with special character but showing question mark("?")
code-
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?;
i database table all field type is varchar(50) i getting this problem in java database is mysql please help me thanks in advance
Upvotes: 0
Views: 1297
Reputation: 450
INSERT INTO gauges (degreeValue,degreeValue1,degreeValue2) VALUES("56° 16’ 44’","56° 16’ 45’","56° 16’ 46'");
SELECT * FROM gauges;
Result :
56° 16’ 44’
56° 16’ 45’
56° 16’ 46'
Insert Your values in "" (Double Quote)directly
Upvotes: 0
Reputation: 1331
You need to escape special characters before inserting into the database
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:
Here are some examples of how to include special characters:
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
Upvotes: 2