Hello!
I do a WebSoket in Java and ran into a problem related to utf-8 encoding. DB took with Heroku (ClearDB), also checked insert into in MySQL itself. Everything works, but not via JDBC.
Created a table in MySQL:
CREATE TABLE `heroku_4af59489dcca747`.`message` ( `idmessage` INT NOT NULL AUTO_INCREMENT, `idincoming` INT NOT NULL, `idoutgoing` INT NOT NULL, `content` VARCHAR(250) NOT NULL, `date` VARCHAR(10) NOT NULL, PRIMARY KEY (`idmessage`)) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8; Added to JDBC here is this code:
private URI dbUri = new URI(System.getenv("CLEARDB_DATABASE_URL")); private final String url = "jdbc:mysql://" + dbUri.getHost() + dbUri.getPath(); private final String login = dbUri.getUserInfo().split(":")[0]; private final String password = dbUri.getUserInfo().split(":")[1]; private Connection connection; private Statement statement; connection = DriverManager.getConnection(url, login, password); statement = connection.createStatement(); In the project settings, heroku changed the Config Variables
CLEARDB_DATABASE_URL mysql://{login}:{pass}@eu-cdbr-west-01.cleardb.com/heroku_4af59489dcca747?useUnicode=true&characterEncoding=UTF-8 Then I make a "request"
try { statement.execute("insert into message (idincoming,idoutgoing,content,date) values (1,2, 'Привет', '23:11')"); } catch (Exception e) { e.printStackTrace(); } And where the 'Hello' characters are introduced '??????'
What could be the problem?