public static JdbcTemplate connectBDD() {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://localhost:8080/test");
ds.setUsername("root");
ds.setPassword("root");
JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
jdbcTemplate.setDataSource(ds);
return jdbcTemplate;
}
Thanks to these lines of code I'm able to make queries to my database.
I've seen so many people doing the same thing using an xml file that contains all the information to connect to a database.
Can someone show me please how to write such a file and most importantly how to invoke it in the java code.
Thank you !