⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guidehibernatedao.java~137~

📁 hibernate+spring的相片上传项目
💻 JAVA~137~
字号:
package org.lenovoAC.hibernateDao;

import org.lenovoAC.pojo.Guide;
import java.util.List;
import org.lenovoAC.dao.GuideDao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import net.sf.hibernate.Session;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * 客户服务
   投保/缴费/索陪指南(客户服务)表:guide

 * @author not attributable
 * @version 1.0
 */
public class GuideHibernateDao
    extends BaseDao
{
  /**
   * 添加
   * @param gu Guide
   */
  public void insertGuide(Guide gu)
      throws Exception
  {
    this.getHibernateTemplate().save(gu);

    Connection con= null;
    ResultSet rs=null;
    Session session=this.getSession();
    con=session.connection();
    con.setAutoCommit(false);
    String sql="select * from GUIDE where id='"+gu.getId()+"' for update";
    PreparedStatement ps = con.prepareStatement(sql);
    rs=ps.executeQuery();
    if(rs.next())
    {
      oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CONTEXT");
      java.io.Writer out=clob.getCharacterOutputStream();
      out.write(gu.getContext());
      out.close();
      con.commit();
      con.close();
    }

  }

  /**
   * 修改
   * @param gu Guide
   */
  public void updateGuide(Guide gu)
      throws Exception
  {
    /*net.sf.hibernate.Session session=null;
    java.sql.Connection con=null;
    java.sql.PreparedStatement ps=null;
    try
    {
      String sql="update GUIDE set Title=?,context=?,state=?,Time=sysdate where id=?";
      session=this.getSession();
      con=session.connection();
      ps=con.prepareStatement(sql);
      ps.setString(1,gu.getTitle());
      ps.setString(2,gu.getContext());
      ps.setString(3,gu.getState());
      ps.setString(4,gu.getId());
      ps.executeUpdate();
      ps.close();
      con.close();
      session.close();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }*/

  Connection con= null;
  ResultSet rs=null;
  Session session=this.getSession();
  con=session.connection();
  con.setAutoCommit(false);
  String sql="select * from GUIDE where id='"+gu.getId()+"' for update";
  PreparedStatement ps = con.prepareStatement(sql);
  rs=ps.executeQuery();
  if(rs.next())
  {
    oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CONTEXT");
    java.io.Writer out=clob.getCharacterOutputStream();
    out.write(gu.getContext());
    out.close();
    con.commit();
    con.close();
  }


  }

  /**
   * 删除
   * @param gu Guide
   */
  public void delGuide(Guide gu)
  {
    this.getHibernateTemplate().delete(gu);
  }

  /**
   * 通过ID得到实例
   * @param id String
   * @return Guide
   */
  public Guide getGuide(String id)
  {
    return (Guide)this.getHibernateTemplate().load(Guide.class, id);
  }

  /**
   * 删除ID指定的对象
   * @param id String
   */
  public void delGuideTwo(String id)
  {
    Guide gu = getGuide(id);
    delGuide(gu);
  }
  /**
   * 修改指定ID的值为GuOld的值
   * @param id String
   * @param guOld Guide
   */
  public void updateGuideTwo(String id,Guide guOld)
      throws Exception
  {
    Guide guNew = getGuide(id);
    guNew.setTitle(guOld.getTitle());
    guNew.setContext(guOld.getContext());
    guNew.setState(guOld.getState());
    guNew.setTime(guOld.getTime());
    this.updateGuide(guNew);
  }
  /**
   * 读出所有记录
   * @return List
   */
  public List getAllGuide()
  {
    return this.getHibernateTemplate().loadAll(Guide.class);
  }
  /**
   * 读出所有记录,通过时间排序
   * @return List
   */
  public List getAllGuideTwo()
  {
    String hql="from Guide as gu order by gu.time desc";
    return this.getHibernateTemplate().find(hql);
  }
  /**
   * 取得ID对象的类型值
   * @param id String
   * @return String
   */
  public String getState(String id)
  {
    return this.getGuide(id).getState();
  }
}





















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -