In order to get a connection, we need to configure DataSource in the configuration. A DataSource is a class which contains configuration information using which it creates connection object. A class which implements javax.sql.DataSource Interface can be configured as a DataSource spring bean. Spring provides one of the implementations of javax.sql.DataSource interface as part of its core package which is DriverManagerDataSource. This class is similar to DriverManager class in a traditional JDBC application. For this class we need to set the properties like DriverClass, Url, Username and Password for creating a connection. The sample configuration has been show in the below fragment.
persistence-beans.xml
<bean id=”dataSource” class=”org.springframework.jdbc.datasource.DriverManagerDataSource”> <property name=”url” value=”jdbc:oracle:thin:@//localhost:1521/xe”/> <property name=”username” value=”hr”/> <property name=”password” value=”hr”/> <property name=”driverClassName” value=”oracle.jdbc.driver.OracleDriver”/> </bean></pre>
Thanks for reading. If you like this post please follow us for more updates about technology related updates.
No comments:
Post a Comment