DriverManager.getConnection("jdbc:mysql:localhost:3306/testdb","root","root");
(or)
DataSource ds = new {some class which implements DataSource interface};
ds.getConnection("root","root");
Using DataSource is preferred over DriverManager.getConnection();
Every tutorial suggest to use DataSource since it is having some advantages over DriverManager. As far as i know, (correct me if i am wrong) connection pooling is the main benefit we will get in DataSource(may be other benefits also).
In that case, if my requirement is i need connection pooling in my Desktop java application then how can i implement that?. Please dont confuse me with JNDI blah blah....
is it something like which database i'm using (mysql) that vendor should provide a class that implements DataSource interface. eg: MysqlDataSource.
if so... will the below code is correct...? and does it provide me the connection pool benefit? how can i ensure that?
MysqlDataSource ds = new MysqlDataSource();
ds.setUrl("jdbc:mysql://localhost:3306/testdb");
ds.setUser("root");
ds.setPassword("root");
Connection connection = ds.getConnection();