Spring's jdbc "Inherit Jdbcdaosupport"

Source: Internet
Author: User
Tags aop

The DAO layer class Userdaoimpl inherits Jdbcdaosupport and cancels annotations on the class, overwrites the previous temp object to Getjdbctemplate (), and then configures the Userdaoimpl Bean in the spring IOC container. and inject the DataSource in.

The global configuration file Beans.xml is as follows:

<?xml version="1.0"encoding="UTF-8"? ><beans xmlns="Http://www.springframework.org/schema/beans"XMLNS:AOP="HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"Xmlns:context="Http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"xsi:schemalocation="Http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd http:www.springframework.org/schema/Context http:www.springframework.org/schema/context/spring-context.xsd http:www.springframework.org/schema/AOP http:Www.springframework.org/schema/aop/spring-aop.xsd"><context:component-scan base-package="com"/> <bean id="DS"class="Com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="User"Value="Root"/> <property name="Password"Value="Root"/> <property name="Jdbcurl"Value="jdbc:mysql:///db_test"/> <property name="Driverclass"Value="Com.mysql.jdbc.Driver"/> </bean> <bean id="DAO"class="Com.dao.UserDaoImpl"> <property name="DataSource"ref="DS"/> </bean></beans>

The Userdaoimpl code is as follows:

Public class Userdaoimpl extends Jdbcdaosupport implements Userdao {@Override public boolean Add (user user) { String SQL="INSERT into user values (?,?,?,?)"; int update=getjdbctemplate (). Update (SQL, User.getid (), User.getname (), User.getage (), user.getaddress ()); returnUpdate >0?true:false; } @Override public boolean update (user user) {String SQL="Update user set name=?, age=?, address=? where id=?"; int update=getjdbctemplate (). Update (SQL, User.getname (), User.getage (), user.getaddress (), User.getid ()); returnUpdate >0?true:false; }
}

Spring's jdbc "Inherit Jdbcdaosupport"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.