I'm leaning docker and trying to connect a db in my java application.
I already create the container and started it
5621fc9b438d mysql/mysql-server:latest "/entrypoint.sh mysq About an hour ago Up About an hour 3306/tcp mysql-db
I also accessed the container and create one database by bash. I'm having problem to connect the db on Java class.
My Java method
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost/mydb");
dataSource.setUsername("mysql-db");
dataSource.setPassword("root");
return dataSource;
}
How can I connect and use my docker mysql database on Java application?