Announcement Announcement Module
Collapse
No announcement yet.
Spring Framework DAO tutorial Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Framework DAO tutorial

    I need help in this Spring Framework DAO class.

    tutorial : http://static.springsource.org/docs/...5.html#step5.5

    I need a concept help.

    Here is the DAO code from the above tutorial.

    Code:
    package springapp.repository;
    
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.List;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
    import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
    import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
    
    import springapp.domain.Product;
    
    public class JdbcProductDao extends SimpleJdbcDaoSupport implements ProductDao {
    
        /** Logger for this class and subclasses */
        protected final Log logger = LogFactory.getLog(getClass());
    
    
        public List<Product> getProductList() {
            logger.info("Getting products!");
            List<Product> products = getSimpleJdbcTemplate().query(
                    "select id, description, price from products",
                    new ProductMapper());
            return products;
        }
    
        public void saveProduct(Product prod) {
            logger.info("Saving product: " + prod.getDescription());
            int count = getSimpleJdbcTemplate().update(
                "update products set description = :description, price = :price where id = :id",
                new MapSqlParameterSource().addValue("description", prod.getDescription())
                    .addValue("price", prod.getPrice())
                    .addValue("id", prod.getId()));
            logger.info("Rows affected: " + count);
        }
       
        private static class ProductMapper implements ParameterizedRowMapper<Product> {
    
            public Product mapRow(ResultSet rs, int rowNum) throws SQLException {
                Product prod = new Product();
                prod.setId(rs.getInt("id"));
                prod.setDescription(rs.getString("description"));
                prod.setPrice(new Double(rs.getDouble("price")));
                return prod;
            }
    
        }
    
    }

    Question :
    =========


    I am wondering How this DAO class is getting database connection ?

    I believe in order to get connection , I need to put the jdbc.properties file in the classpath.

    'springapp/war/WEB-INF/classes/jdbc.properties':
    Code:
    jdbc.driverClassName=org.hsqldb.jdbcDriver
    jdbc.url=jdbc:hsqldb:hsql://localhost
    jdbc.username=sa
    jdbc.password=

    but is that all configuration ? OR do we need any other configuration file for database connection ?
    Last edited by andromeda; Nov 17th, 2009, 04:38 AM.
Working...
X