Configuring Data Source by R4R Team

Configuring Data Source:-

Let us create a database table Employee in our database Test. I assume you are working with MySQL database, if you work with any other database then you can change your DDL and SQL queries accordingly.

CREATE TABLE EMPLOYEE(

ID INT NOT NULL AUTO_INCREMENT,

NAME VARCHAR(20) NOT NULL,

SALARY INT NOT NULL,

PRIMARY KEY (ID)

);

Now we need to provide a DataSource to the JdbcTemplate so it can configure itself to get database access. You can configure the DataSource in the XML file with a piece of code as shown below:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="com.mysql.jdbc.Driver"/>

<property name="url" value="jdbc:mysql://localhost:3306/Test"/>

<property name="username" value="root"/>

<property name="password" value="password"/>

</bean>

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!