I'm having trouble sending or displaying text with special characters from my webservice to my database. On my eclipse I have set the character encoding to UTF-8 but it still doesn't let me display the characters. For example a simple print like the code below
String test ="привет";
System.out.println(test);
OR
String test ="привет";
String query = "insert into communication (`test`) VALUES ('"+ test +"');
PreparedStatement preparedStmt1 = con.prepareStatement(query);
preparedStmt1.executeUpdate();
The result on the console and if I send this to my database is ??????. How do I get this to display correctly on the console and hopefully in the database
If you are using Eclipse, then
See if this works.
PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.println(test);
For storing in DB, use following to explicitly encode the string in UTF-8
String newString = new String(test.getBytes(), "UTF8");
Yeah, its the XXI. century and we're still struggling with things like character encoding...
My first guess is that either:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With