免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
struct加Ajax(2)

com.san.strutsAjax.business.CusotmerDAO (DAO接口)

package com.san.strutsAjax.business;

import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: huxinsheng
 * Date: 2006-4-9
 * Time: 12:52:47
 * To change this template use File | Settings | File Templates.
 */
public interface CusotmerDAO {
    public void insertCustomer(Object obj)throws Exception;
    public List queryAllCustomer()throws Exception;
    public List queryCustomerByCondition(Map condition)throws Exception;
    public void deleteCustomer(Map condition)throws Exception;
}

 

 

com.san.strutsAjax.business.CustomerDAOImpl(DAO實現(xiàn))

package com.san.strutsAjax.business.impl;

import com.san.strutsAjax.business.CusotmerDAO;
import com.san.strutsAjax.utils.ConnectionDB;
import com.san.strutsAjax.utils.EngenderID;
import com.san.strutsAjax.forms.CustomerForm;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.log4j.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: huxinsheng
 * Date: 2006-4-9
 * Time: 12:54:26
 * To change this template use File | Settings | File Templates.
 */
public class CustomerDAOImpl implements CusotmerDAO {
    Logger log = Logger.getLogger(CustomerDAOImpl.class);
    Connection conn = null;
    PreparedStatement pstmt;

    {
        pstmt = null;
    }

    ResultSet res = null;


    String sql = null;


    public void insertCustomer(Object obj) throws Exception {
        CustomerForm form = (CustomerForm) obj;
        int id = EngenderID.engenderTableId("CUSTOMERS");
        System.out.println("" + form);
        sql = "INSERT INTO CUSTOMERS VALUES(?,?,?,?,?,?)";

        try {
            conn = ConnectionDB.ConnectToDb();
            conn.setAutoCommit(false);

            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, id);
            pstmt.setString(2, form.getName());
            pstmt.setInt(3, form.getAge());
            pstmt.setInt(4, form.getTelephone());
            pstmt.setString(5, form.getAddress());
            pstmt.setInt(6, form.getPostcode());
            pstmt.executeUpdate();
            conn.commit();
            log.info("保存數(shù)據(jù)成功");
        } catch (Exception e) {
            log.debug(e.getMessage());
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } finally {
            log.info("關(guān)閉連接");
            conn.close();
        }

    }

    public List queryCustomerByCondition(Map condition) throws Exception {
        Integer id = Integer.parseInt((String) condition.get("id"));
        System.out.println(id);
        String sql = "SELECT * FROM CUSTOMERS WHERE ID=?";
       // System.out.println(sql);
        try {
            conn = ConnectionDB.ConnectToDb();
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, id);
            res = pstmt.executeQuery();
            return getResultDTO(res);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("業(yè)務(wù)層數(shù)據(jù)訪問出錯: " + e.getMessage());
            return null;
        } finally {
            log.info("關(guān)閉連接");
            conn.close();
        }
    }

    public List queryAllCustomer() throws Exception {
        String sql = "SELECT * FROM CUSTOMERS";
        try {
            conn = ConnectionDB.ConnectToDb();
            pstmt = conn.prepareStatement(sql);
            res = pstmt.executeQuery();
            return getResults(res);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("業(yè)務(wù)層數(shù)據(jù)訪問出錯: " + e.getMessage());
            return null;
        } finally {
            log.info("關(guān)閉連接");
            conn.close();
        }
    }

    public List getResultDTO(ResultSet res) throws Exception {
        List results = new ArrayList();
        CustomerForm customer;
        if (res.next()) {
            customer = new CustomerForm();
            customer.setId(res.getInt("ID"));
            customer.setName(res.getString("CUSTNAME"));
            customer.setAge(res.getInt("AGE"));
            customer.setTelephone(res.getInt("TELEPHONE"));
            customer.setAddress(res.getString("ADDRESS"));
            customer.setPostcode(res.getInt("POSTCODE"));
            results.add(customer);
        }
        System.out.println(results);
        return results;
    }

    public List getResults(ResultSet res) throws Exception {
        List results = new ArrayList<CustomerForm>();
        CustomerForm customer;
        while (res.next()) {
            customer = new CustomerForm();
            customer.setId(res.getInt("ID"));
            customer.setName(res.getString("CUSTNAME"));
            customer.setAge(res.getInt("AGE"));
            customer.setTelephone(res.getInt("TELEPHONE"));
            customer.setAddress(res.getString("ADDRESS"));
            customer.setPostcode(res.getInt("POSTCODE"));
            results.add(customer);
        }
        return results;
    }

    public void deleteCustomer(Map condition) throws Exception {
        //To change body of implemented methods use File | Settings | File Templates.
    }
}

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JDBC讀取新插入Oracle數(shù)據(jù)庫Sequence值的5種方法
Java開發(fā)經(jīng)驗總結(jié)_熊強
Java調(diào)用SQL Server存儲過程同時返回參數(shù)和結(jié)果集
數(shù)據(jù)庫連接池DBCP
java swing jdbc sql 增刪改查 實例1
歡迎光臨 - 琳婕小筑-老貓的理想 - 通過JDBC操作ORACLE數(shù)據(jù)庫實例詳解 -
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服