java应用程序修改数据库

配置和BS差不多,附上程序

1、用来传输对象的DTO

package com.yihaodian.pis.dto;
import java.io.Serializable;
public class SiteCategoryDto implements Serializable
{
    private static final long serialVersionUID = -8202969095017554696L;
    /**
     * 分类id
     */
    private Integer id;
    /**
     * 网站id
     */
    private Integer siteId;
    /**
     * 分类名称
     */
    private String categoryName;
    /**
     * 分类产品列表对应的url
     */
    private String categoryUrl;
    /**
     * 父分类id
     */
    private Integer parentCategoryId;
    /**
     * 分类级别
     */
    private Integer categoryLevel;
    /**
     * 商品抓取数量
     */
    private Integer fetchSize;
    
    
    /**
     * 网站名称
     */
    private String siteName;
    
    /**
     * 父亲分类名称
     */
    private String parentName;
    public Integer getId()
    {
        return id;
    }
    public void setId(Integer id)
    {
        this.id = id;
    }
    public Integer getSiteId()
    {
        return siteId;
    }
    public void setSiteId(Integer siteId)
    {
        this.siteId = siteId;
    }
    public String getCategoryName()
    {
        return categoryName;
    }
    public void setCategoryName(String categoryName)
    {
        this.categoryName = categoryName;
    }
    public String getCategoryUrl()
    {
        return categoryUrl;
    }
    public void setCategoryUrl(String categoryUrl)
    {
        this.categoryUrl = categoryUrl;
    }
    public Integer getParentCategoryId()
    {
        return parentCategoryId;
    }
    public void setParentCategoryId(Integer parentCategoryId)
    {
        this.parentCategoryId = parentCategoryId;
    }
    public Integer getCategoryLevel()
    {
        return categoryLevel;
    }
    public void setCategoryLevel(Integer categoryLevel)
    {
        this.categoryLevel = categoryLevel;
    }
    public Integer getFetchSize()
    {
        return fetchSize;
    }
    public void setFetchSize(Integer fetchSize)
    {
        this.fetchSize = fetchSize;
    }
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append("SiteCategory [id=");
        builder.append(id);
        builder.append(", siteId=");
        builder.append(siteId);
        builder.append(", categoryName=");
        builder.append(categoryName);
        builder.append(", categoryUrl=");
        builder.append(categoryUrl);
        builder.append(", fetchSize=");
        builder.append(fetchSize);
        builder.append(", categoryLevel=");
        builder.append(categoryLevel);
        builder.append(", parentCategoryId=");
        builder.append(parentCategoryId);
        builder.append("]");
        return builder.toString();
    }
    public String getSiteName()
    {
        return siteName;
    }
    public void setSiteName(String siteName)
    {
        this.siteName = siteName;
    }
    public String getParentName()
    {
        return parentName;
    }
    public void setParentName(String parentName)
    {
        this.parentName = parentName;
    }
}

 

2、对数据库操作的DAO

package com.yihaodian.pricehisotry.dao;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.yihaodian.pis.dto.SiteCategoryDto;

/**
 * 畅销商品数据库操作
 */
public class SiteCategoryDao extends SqlMapClientDaoSupport{

    public SiteCategoryDao() {
       
    }

    public int clearSiteCategories(int id) {
        return this.getSqlMapClientTemplate().delete("clearSiteCategories", id);
    }

    /* 
     * 保存分类畅销商品记录
     */
    public void saveSiteCategory(SiteCategoryDto siteCategory) {
        this.getSqlMapClientTemplate().insert("addSiteCategory", siteCategory);
    }
    public Integer getMaxId(){
    	Object count = this.getSqlMapClientTemplate().queryForObject("getMaxId");
    	return Integer.parseInt(count.toString());
    	
    	}
    /** 
     * 添加分类畅销商品记录
     */
    public int addSiteCategory(SiteCategoryDto siteCategory) {
        return (int) ((Long) this.getSqlMapClientTemplate().insert(
                "addSiteCategory", siteCategory)).longValue();
    }
}

 

3、SQLmap对数据库操作的语句





    

    
        
        
        
        
        
        
        
    
	
    
		INSERT INTO
		pis.site_category(site_id,category_name,category_url,parent_category_id,category_level,fetch_size)
		VALUES
		(#siteId#,#categoryName#,#categoryUrl#,#parentCategoryId#,#categoryLevel#,#fetchSize#)
        
                SELECT lastval();
        
    
    
    
		DELETE FROM pis.site_category
		where id=#id#
    

    
		DELETE FROM pis.site_category
		where site_id = #site_id#
    
	
    
    
    
    
    
    
    
    

4、DAO的申明配置

 




    
     
        
		
     

5、连接数据库的配置

 



	
	
	
		
			classpath:jdbc.properties
		
	


	
		
		
		
		
		
		
		
		
		
		
	


	
	
		
			classpath:sqlmap-config.xml
		
		
	




	
	


6、将数据库操作XML引入

 





	
	
	 

你可能感兴趣的:(Java,iBATIS,Bean,Spring,AOP)