I've looked over the documentation to define a bean. I'm just unclear on what class file to use for a Mysql database. Can anyone fill in the bean definition below?
<bean name="dataSource" class="">
<property name="driverClassName" value="" />
<property name="url" value="mysql://localhost/GameManager" />
<property name="username" value="gamemanagertest" />
<property name="password" value="1" />
</bean>
http://docs.spring.io/spring-data/jdbc/docs/1.1.0.M1/reference/html/orcl.datasource.html
Use this class
org.springframework.jdbc.datasource.DriverManagerDataSource
- DriverManagerDataSource. As a best practice its better if we isolate the database values into a.properties
file and configure it into our spring servlet xml configuration. In the below example the properties are stored as key-value pairs and we access thevalue
using the correspondingkey
.applicationContext-dataSource.xml:
jdbc.propeties file:
Both the answers are appropriate for the question. But just for an FYI if you're going to use DriverManagerDataSource as your datasource, every call to your datasource bean will create a new connection to your database which is not recommended for production and even it does not pool connections.
If you need a connection pool, consider Apache Commons DBCP.
Where initialSize and maxActive are pooling related properties.
To use this make sure you have the required jar in your path.