Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF-8 character encoding #40

Closed
catalinfeier opened this issue Mar 4, 2014 · 3 comments
Closed

UTF-8 character encoding #40

catalinfeier opened this issue Mar 4, 2014 · 3 comments

Comments

@catalinfeier
Copy link

I can't seem to be able to get data encoded in UTF-8 (cyrilic , arabic alphabets etc) from my MySQL database. Everything else works correctly and as expected.
Without HikariCP (no connection pooling) I used "useUnicode=true&characterEncoding=UTF-8" as a property for my connection and it worked.
With HikariCP i tried something similar for the configuration:
config.addDataSourceProperty("url", "jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF-8");
I also tried using the following:
config.addDataSourceProperty("characterEncoding",Charsets.UTF_8.name());
config.addDataSourceProperty("useUnicode","true");
Neither worked, the cyrilic characters were shown as ???.
My MySQL version is 5.5.27, but like i said without using connection pooling the character were shown correctly.
Any suggestions/ideas?

@brettwooldridge
Copy link
Owner

Oh, I thought my answer was wrong after I posted it so I deleted it. I'll attach it here again in case another user has the same issue. Set the encoding like this:

config.addDataSourceProperty("characterEncoding","utf8");
config.addDataSourceProperty("useUnicode","true");

@dimkir
Copy link

dimkir commented Mar 4, 2014

Maybe someone finds useful to specify the encoding in hikari.properties file like this:

acquireIncrement=3
acquireRetryDelay=1000
connectionTestQuery=SELECT 1
dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
dataSource.user=yourUser
dataSource.password=yourPassword
dataSource.databaseName=your_database
dataSource.serverName=localhost
dataSource.encoding=UTF-8
           ^^^^^^^^^^^^^^

This seems to work for me well.

@AyubOpen
Copy link

AyubOpen commented Jul 9, 2017

@brettwooldridge sorry for messaging on a closed thread, I am trying the same appoarch as you mentioned about config.add for utf-8, but I still see the issue of garbled characters. Code works if I use plain jdbc; below is my property file

//hikari.properties
driverClassName=oracle.jdbc.driver.OracleDriver
jdbcUrl=jdbc:oracle:thin:@localhost:1521/xe
maximumPoolSize=20
username=testdbapp
password=oracle
dataSource.cachePrepStmts=true
dataSource.prepStmtCacheSize=250

@configuration
public class AppConfig {

@Bean(destroyMethod = "close")
public DataSource dataSource() throws SQLException {
    HikariConfig config = new HikariConfig("/hikari.properties");
    config.addDataSourceProperty("characterEncoding","utf8"); //tried with UTF-8 as well
    config.addDataSourceProperty("useUnicode","true");
    HikariDataSource dataSource = new HikariDataSource(config);

    return dataSource;
}

}

this is a spring boot application, please advise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants