zoukankan      html  css  js  c++  java
  • Example With JdbcDaoSupport

    By extended the JdbcDaoSupport, set the datasource and JdbcTemplate in your class is no longer required, you just need to inject the correct datasource into JdbcCustomerDAO. And you can get the JdbcTemplate by using a getJdbcTemplate() method.

    public class JdbcCustomerDAO extends JdbcDaoSupport implements CustomerDAO
    {
       //no need to set datasource here
       public void insert(Customer customer){
    
        String sql = "INSERT INTO CUSTOMER " +
            "(CUST_ID, NAME, AGE) VALUES (?, ?, ?)";
    
        getJdbcTemplate().update(sql, new Object[] { customer.getCustId(),
                customer.getName(),customer.getAge()
        });
    
    }
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
        <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/mkyongjava" />
            <property name="username" value="root" />
            <property name="password" value="password" />
        </bean>
    
    </beans>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
        <bean id="customerDAO" class="com.mkyong.customer.dao.impl.JdbcCustomerDAO">
            <property name="dataSource" ref="dataSource" />
        </bean>
    
    </beans>
  • 相关阅读:
    数据分析英国电商——数据分析可视化
    数据分析英国电商——数据预处理部分
    特征工程入门与实践—3 特征增强
    特征工程入门与实践—2 特征理解
    特征工程入门与实践 —1 特征工程简介
    正则表达式匹配
    linux学习笔记
    python深度学习基础
    Linux命令小记1
    AWS S3操作命令
  • 原文地址:https://www.cnblogs.com/MarchThree/p/6128463.html
Copyright © 2011-2022 走看看