乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      struct加Ajax(2)

       WindySky 2007-01-22

      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實(shí)現(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ù)訪問出錯(cuò): " + 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ù)訪問出錯(cuò): " + 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.
          }
      }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多