Hello i am using prepared statement to insert the values into mysql.
I am facing an issue in an string which is inserting as "c2a054656e6e6973c2a0"
for value " Tennis "
and i tried to use trim to trim the whitespace in front of the "Tennis" it did not work .From this question Why trim is not working? i tried using the solution poNumber.replace(String.valueOf((char) 160), " ").trim();
and it worked. can any one give solution for this?
SAMPLE CODE
CREATE TABLE `news1` (
`article_id` int(11) NOT NULL AUTO_INCREMENT,
`article_title` varchar(500) COLLATE utf8_bin NOT NULL,
`article_subcategory` varchar(255) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`article_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=22 ;
//Sample category will be "Home » Tennis"
String category = item.getArticle_category();
String categoryArray[] = category.split("»");
preparedStatement = connect
.prepareStatement("INSERT INTO news1 VALUES(default,?,?)");
System.out.println(categoryArray[2].replace(String.valueOf((char) 160), " ")
.trim());
preparedStatement.setString(1, item.getArticle_title());
preparedStatement.setString(2, categoryArray[2]);