❮ Previous Next ❯

Spring JDBC Introduction

Hi friends, focus to this concept before going to spring JDBC. Here i am presenting the detail introduction to spring JDBC.

We know that we use JDBC technology for persistency purpose, that means connecting with database and performing some operations like insert, update, delete etc. Without using JDBC we cannot able to connect with databases.

But there are some difficulties if a java programmer is directly working with JDBC which is as follows:

To eliminate these above problems, Spring framework has provided one abstraction layer on top of existing JDBC called Spring-JDBC. Here programmers will work with this abstraction layer and that layer will internally uses JDBC technology. So spring-JDBC layer will take cares about connection management and error managements, and programmers will concentrate on their logics.

There is an exception translator provided by spring framework which translates the checked exceptions to un-checked exceptions of spring type and finally the un-checked exceptions are thrown to java programmer. Another advantage is while working with spring-JDBC, the programmer is not required to open and close the database connection, because that will be taken care by the spring framework.

There are two ways to get connection with database like,

Spring framework uses DataSource interface to obtain the connection with database internally, there are two implementation classes and we can use any one of the following classes of DataSource interface.

Here DriverManagerDataSource is given by spring framework and it is equal to DriverManager class, spring framework internally opens a new connection and closes the connection for each operation done on the database.

BasicDataSource is given the apache, and this is better than DriverManagerDataSource because BasicDataSource having inbuilt connection pooling implementation.

In spring configuration file, the following 4 properties that we have to write to get connection with database. The code is like:

<bean id="id2" class="org.springframework.datasource.DriverManagerDataSource">
or
<bean id="id2" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value=" " />
<property name="url" value=" " />
<property name="username" value=" " />
<property name=password" value=" " />
</bean>

❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-N6/530,2ND Floor
Nayapalli,Jayadev Vihar
      Bhubaneswar-751015
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved