zoukankan      html  css  js  c++  java
  • BaseDao

    package dao;
    import java.sql.*;
    public class BaseDao {
    public Connection getCon(){
    Connection con = null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "system", "orcl");
    } catch (Exception e) {
    e.printStackTrace();
    }
    return con;
    }
    public void closeAll(Connection con,Statement stmt,ResultSet rs){
    if(rs != null){
    try {
    rs.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    if(stmt != null){
    try {
    stmt.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    try {
    if(con != null && !con.isClosed()){
    con.close();
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    ===========================================================================================

    package dao;

    import java.io.Serializable;
    import java.util.List;

    import javax.persistence.Entity;
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.Configuration;

    @Entity
    public class BaseDao {
    /**
    * 查找

    */
    public List find(String hql,Object[] args){
    Configuration configuration = new Configuration().configure();
    SessionFactory sessionFactory = configuration.buildSessionFactory();
    Session session = sessionFactory.openSession();
    Query query = session.createQuery(hql);

    for (int i = 0; i < args.length; i++) {
    // query.setEntity( i + 1, args[i]);
    query.setParameter(i, args[i]);
    }
    List list = query.list();
    session.close();
    return list;
    }

    public List find(String hql){
    return this.find(hql, new Object[]{});
    }

    public Object getById(String hql, Serializable id){
    List find = this.find(hql, new Object[]{id});
    if(find.size() > 0 ){
    return find.get(0);
    }
    return null;
    }

    public Object getObject(String hql){
    List find = this.find(hql, new Object[]{});

    return null;
    }


    /**
    * 添加
    * @param objdct
    */
    public void add(Object objdct){
    Configuration configuration = new Configuration().configure();
    SessionFactory sessionFactory = configuration.buildSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    session.save(objdct);
    tx.commit();

    session.close();
    }
    /**
    * 修改
    * @param objdct
    */
    public void edit(Object object){
    Configuration configuration = new Configuration().configure();
    SessionFactory sessionFactory = configuration.buildSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    session.update(object);
    tx.commit();
    session.close();
    }

    /**
    * 修改
    * @param objdct
    */
    public void edit( String hql,Object[] args){
    Configuration configuration = new Configuration().configure();
    SessionFactory sessionFactory = configuration.buildSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    Query query = session.createQuery(hql);
    for (int i = 0; i < args.length; i++) {
    query.setParameter(i, args[i]);
    }
    query.executeUpdate();
    tx.commit();
    session.close();
    }

    }

  • 相关阅读:
    带色彩恢复的多尺度视网膜增强算法(MSRCR)的原理、实现及应用。
    索引图像的那些事啊
    调整图像 自动对比度、自动色阶算法
    图像处理界双线性插值算法的优化
    共享收集的图像处理方面的一些资源和网站。
    Wellner 自适应阈值二值化算法
    基于灰度世界、完美反射、动态阈值等图像自动白平衡算法的原理、实现及效果
    VB6.0用GDI+保存图像为BMP\JPG\PNG\GIF格式终结版。
    关于.net中获取图像缩略图的函数GetThumbnailImage的一些认识。
    限制对比度自适应直方图均衡化算法原理、实现及效果
  • 原文地址:https://www.cnblogs.com/--Candice/p/3629795.html
Copyright © 2011-2022 走看看