Reputation: 905
When trying to set connectionProperties
to "useUnicode=yes;characterEncoding=utf8;"
, is there any difference between this:
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
Properties properties = new Properties();
properties.setProperty("useUnicode", true);
properties.setProperty("characterEncoding", "UTF-8"); // UTF-8 or utf8?
dataSource.setConnectionProperties(properties);
return dataSource;
}
And this?
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactory =
new LocalContainerEntityManagerFactoryBean();
Properties properties = new Properties();
properties.setProperty("hibernate.connection.useUnicode", true);
properties.setProperty("hibernate.connection.characterEncoding", "UTF-8"); // UTF-8 or utf8?
entityManagerFactory.setJpaProperties(properties);
return entityManagerFactory;
}
Or even a third way, just adding them 'raw' to the URL:
jdbc:mysql://localhost:3306/?useUnicode=yes&characterEncoding=UTF-8
Upvotes: 2
Views: 1512
Reputation: 614
As I know there is no difference in these methods of passing connection parameters.
There is configuration parameters of a datasource, they will be passing to 'DriverManager.getConnection()' on connection creation.
All connection properties 'hibernate.connection.' are using for passing to 'DriverManager.getConnection()' too. In most cases it will be internal passing of properties to datasource as in the first scenario.
Yes, you can pass all required parameters by declaring them in jdbc url.
Upvotes: 1