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

📄 seesafetyhibernatedao.java

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

import org.lenovoAC.pojo.SeeSafety;
import java.util.List;
import org.lenovoAC.dao.SeeSafetyDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import java.util.Iterator;
import net.sf.hibernate.Session;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 * 险种博览
   险种博览表: see_safety

 * @author not attributable
 * @version 1.0
 */
public class SeeSafetyHibernateDao
    extends BaseDao
{
  /**
   * 添加
   * @param ss SeeSafety
   */
  public void insertSeeSafety(SeeSafety ss) throws Exception
  {
    this.getHibernateTemplate().save(ss);

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

  }

  /**
   * 修改
   * @param ss SeeSafety
   */
  public void updateSeeSafety(SeeSafety ss)
  {
    this.getHibernateTemplate().update(ss);
  }

  /**
   * 删除
   * @param ss SeeSafety
   */
  public void delSeeSafety(SeeSafety ss)
  {
    this.getHibernateTemplate().delete(ss);
  }

  /**
   * 得到实例
   * @param id String
   * @return SeeSafety
   */
  public SeeSafety getSeeSafety(String id)
  {
    return (SeeSafety)this.getHibernateTemplate().load(SeeSafety.class, id);
  }

  /**
   * 通过ID删除指定对象
   * @param id String
   */
  public void delSeeSafetyTwo(String id)
  {
    SeeSafety ss = this.getSeeSafety(id);
    this.delSeeSafety(ss);
  }

  /**
   * 修改指定ID的值为指定对象值
   * @param id String
   * @param ssOld SeeSafety
   */
  public void updateSeeSafetyTwo(SeeSafety ss) throws Exception
  {
    /*Session session=null;
         java.sql.Connection con=null;
         java.sql.PreparedStatement ps=null;
         try
         {
      String sql="update SEE_SAFETY set name=?,Type=?,Intro=?,Time=sysdate,state=?,Commend_state=? where id=?";
      session=this.getSession();
      con=session.connection();
      ps=con.prepareStatement(sql);
      ps.setString(1,ssOld.getName());
      ps.setString(2,ssOld.getType());
      ps.setString(3,ssOld.getIntro());
      ps.setString(4,ssOld.getState());
      ps.setString(5,ssOld.getCommendState());
      ps.setString(6,ssOld.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 sqlTwo = "update SEE_SAFETY set name=?,Type=?,INTRO=empty_clob(),Time=sysdate,state=?,Commend_state=? where id=?";
    PreparedStatement ps2 = con.prepareStatement(sqlTwo);
    ps2.setString(1, ss.getName());
    ps2.setString(2, ss.getType());
    ps2.setString(3, ss.getState());
    ps2.setString(4, ss.getCommendState());
    ps2.setString(5, ss.getId());
    ps2.executeUpdate();

    String sql = "select * from SEE_SAFETY where id='" + ss.getId() +
        "' for update";
    PreparedStatement ps = con.prepareStatement(sql);
    rs = ps.executeQuery();
    if (rs.next())
    {
      oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob("INTRO");
      java.io.Writer out = clob.getCharacterOutputStream();
      out.write(ss.getIntro());
      out.close();
      con.commit();
      con.close();
    }

  }

  /**
   * 得到显示标志
   * @param id String
   * @return String
   */
  public String getState(String id)
  {
    SeeSafety ss = this.getSeeSafety(id);
    return ss.getState();
  }

  /**
   * 得到推荐标志
   * @param id String
   * @return String
   */
  public String getCommendState(String id)
  {
    SeeSafety ss = this.getSeeSafety(id);
    return ss.getCommendState();
  }

  /**
   * 得到全部记录
   * @return List
   */
  public List getAllSeeSafety()
  {
    return this.getHibernateTemplate().loadAll(SeeSafety.class);
  }

  /**
   * 得到全部记录(通过时间排序,降序)
   * @return List
   */
  public List getAllSeeSafetyTwo()
  {
    String hql = "from SeeSafety as ss order by ss.time desc";
    return this.getHibernateTemplate().find(hql);
  }

  public List getAllSeeSafetyThree()
  {
    String hql =
        "from SeeSafety as ss where ss.state='01' order by ss.time desc";
    return this.getHibernateTemplate().find(hql);
  }

}

⌨️ 快捷键说明

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