package hello1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;

import hello1.myUser;
import hello1.myUserDAO;

class JdbcmyUserDAO implements myUserDAO {
    private DataSource dataSource;
    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }
    public void insert(myUser user) {
    }
    public myUser findById(int id) {
        String sql = "select id, name, age from myuser where id = ?";
        Connection conn = null;
        try {
            conn = this.dataSource.getConnection();
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setInt(1, id);
            ResultSet resultSet =  preparedStatement.executeQuery();
            myUser u = null;
            if (resultSet.next()) {
                u = new myUser(
                        resultSet.getInt("id"),
                        resultSet.getString("name"),
                        resultSet.getInt("age"));
            }
            resultSet.close();
            preparedStatement.close();
            return u;
        }catch(SQLException e) {
        }finally {
        }
        return null;
    }
}

@@ -158,16 +158,125 @@
 aSource;
+%0Aimport org.springframework.jdbc.core.support.JdbcDaoSupport;%0Aimport org.springframework.jdbc.core.RowMapper;
 %0A%0Aimport
@@ -337,16 +337,39 @@
 UserDAO 
+extends JdbcDaoSupport 
 implemen
@@ -383,16 +383,23 @@
 erDAO %7B%0A
+    /*%0A
     priv
@@ -520,24 +520,31 @@
 urce;%0A    %7D%0A
+    */%0A
     public v
@@ -608,24 +608,54 @@
 d(int id) %7B%0A
+        /*  use jdbc directly%0A
         Stri
@@ -1430,19 +1430,561 @@
     
-return null
+*/%0A%0A        // use JdbcTemplate%0A        myUser a = this.getJdbcTemplate().queryForObject(%0A                %22select id, name, age from myuser where id = ?%22,%0A                new Object%5B%5D%7Bid%7D,%0A                new RowMapper%3CmyUser%3E() %7B%0A                        public myUser mapRow(ResultSet rs, int rowNum) throws SQLException %7B%0A                            myUser u = new myUser(rs.getInt(%22id%22), rs.getString(%22name%22), rs.getInt(%22age%22));%0A                            return u;%0A                        %7D%0A                    %7D%0A                );%0A        return a
 ;%0A  

use jdbctemplate replace use jdbc directly