List of usage examples for org.hibernate SQLQuery setParameter
@Override NativeQuery<T> setParameter(int position, Object val);
From source file:com.sistcontable.dao.CuentaDAO.java
public Cuenta obtenerCuentaByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w w w . j ava2 s. com*/ List<Cuenta> lista = new ArrayList(); try { String query = "select * from cuenta where ID_CUENTA=:idCuenta"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Cuenta.class); sqlQuery.setParameter("idCuenta", id); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Cuenta cuenta = (Cuenta) result.get(i); System.out.println("idCuenta: " + cuenta.getIdCuenta()); System.out.println("estado: " + cuenta.getEstado().getNombreEstado()); System.out.println("rubro: " + cuenta.getRubro().getNombreRubro()); System.out.println("nombreCuenta: " + cuenta.getNombreCuenta()); System.out.println("cuentaMayor: " + cuenta.getCuentaMayor()); } return (Cuenta) result.get(0); } catch (Exception e) { System.out.println("ERROR " + e); lista = null; return null; } finally { session.close(); } }
From source file:com.sistcontable.dao.EstadoDAO.java
public void searchEstadoByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w . j a va2s . c o m List<Estado> lista = new ArrayList(); try { String query = "select * from estado where ID_ESTADO=:idEstado"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Estado.class); sqlQuery.setParameter("idEstado", id); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Estado estado = (Estado) result.get(i); System.out.println("idEstado: " + estado.getIdEstado()); System.out.println("nombreEstado: " + estado.getNombreEstado()); System.out.println("disponibilidad: " + estado.getDisponibilidad()); } } catch (Exception e) { System.out.println("ERROR " + e); lista = null; } finally { session.close(); } }
From source file:com.sistcontable.dao.EstadoDAO.java
public Estado obtenerEstadoByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w . ja v a2 s. c o m List<Estado> lista = new ArrayList(); try { String query = "select * from estado where ID_ESTADO=:idEstado"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Estado.class); sqlQuery.setParameter("idEstado", id); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Estado estado = (Estado) result.get(i); System.out.println("idEstado: " + estado.getIdEstado()); System.out.println("nombreEstado: " + estado.getNombreEstado()); System.out.println("disponibilidad: " + estado.getDisponibilidad()); } return (Estado) result.get(0); } catch (Exception e) { System.out.println("ERROR " + e); lista = null; return null; } finally { session.close(); } }
From source file:com.sistcontable.dao.RubroDAO.java
public void searchRubroByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w ww .j a va2 s .c o m*/ List<Rubro> lista = new ArrayList(); try { String query = "select * from rubro where ID_RUBRO=:idRubro"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Rubro.class); sqlQuery.setParameter("idRubro", id); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Rubro rubro = (Rubro) result.get(i); System.out.println("idRubro: " + rubro.getIdRubro()); System.out.println("nombreRubro: " + rubro.getNombreRubro()); System.out.println("tipoRubro: " + rubro.getTipoRubro()); } } catch (Exception e) { System.out.println("ERROR " + e); lista = null; } finally { session.close(); } }
From source file:com.sistcontable.dao.RubroDAO.java
public Rubro obtenerRubroByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//www .ja v a2 s . c o m List<Rubro> lista = new ArrayList(); try { String query = "select * from rubro where ID_RUBRO=:idRubro"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Rubro.class); sqlQuery.setParameter("idRubro", id); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Rubro rubro = (Rubro) result.get(i); System.out.println("idRubro: " + rubro.getIdRubro()); System.out.println("nombreRubro: " + rubro.getNombreRubro()); System.out.println("tipoRubro: " + rubro.getTipoRubro()); } return (Rubro) result.get(0); } catch (Exception e) { System.out.println("ERROR " + e); lista = null; return null; } finally { session.close(); } }
From source file:com.sistcontable.dao.UsuarioDAO.java
public void searchUserByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*www . j a v a 2 s . c om*/ List<Usuario> lista = new ArrayList(); try { String query = "select * from usuario where id_usuario=:id_usuario"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Usuario.class); sqlQuery.setParameter("id_usuario", id); //lista=sqlQuery.list(); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Usuario usuario = (Usuario) result.get(i); System.out.println("id_usuario: " + usuario.getId_usuario()); System.out.println("id_persona: " + usuario.getId_persona()); System.out.println("nombre_usuario: " + usuario.getNombre_usuario()); System.out.println("clave: " + usuario.getClave()); } } catch (Exception e) { System.out.println("ERROR " + e); lista = null; } finally { session.close(); } }
From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java
/** * ????/*from w w w . ja va2 s. co m*/ * @param vendorName * @return */ @SuppressWarnings("unchecked") public List<Vendor> GetAVendor(String vendorName) { String sql = "select t.vendorcode,t.vendorname from t_vendor t where t.vendorname=?"; SQLQuery query = dao.getHibernateSession().createSQLQuery(sql); SetAVendor(query); query = (SQLQuery) query.setResultTransformer(Transformers.aliasToBean(Vendor.class)); query.setParameter(0, vendorName); return query.list(); }
From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java
/** * ?????/* w w w . ja v a 2 s .c o m*/ * @param vo * @return */ public int GetAVenderCode(Vendor vo) { int result = 0; String sql = "select * from (select t.vendorcode" + " from t_vendor t" + " where t.sector=? order by t.vendorcode desc)" + " where rownum=1"; SQLQuery query = dao.getHibernateSession().createSQLQuery(sql); query.setParameter(0, vo.getSector()); Object obj = query.uniqueResult(); if (obj == null || obj.toString().equals("")) { //?? if (vo.getSector().equals("")) result = 781000; else if (vo.getSector().equals("")) result = 611000; else if (vo.getSector().equals("")) result = 621000; else if (vo.getSector().equals("")) result = 631000; else if (vo.getSector().equals("")) result = 641000; else if (vo.getSector().equals("")) result = 651000; else if (vo.getSector().equals("?")) result = 661000; else if (vo.getSector().equals("")) result = 671000; else if (vo.getSector().equals("")) result = 681000; else if (vo.getSector().equals("")) result = 691000; else if (vo.getSector().equals("")) result = 701000; else if (vo.getSector().equals("")) result = 711000; else if (vo.getSector().equals("")) result = 721000; else if (vo.getSector().equals("??")) result = 731000; else if (vo.getSector().equals("")) result = 741000; else if (vo.getSector().equals("")) result = 751000; else if (vo.getSector().equals("?")) result = 761000; else if (vo.getSector().equals("?")) result = 771000; } else { result = Integer.parseInt(obj.toString()) + 1; } // System.out.println("?"+result); return result; }
From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java
/** * ????????/* www . jav a 2 s .c o m*/ * @param vo * @return */ public int UpdateAVendor(Vendor vo) { String sql = "update t_vendor v set v.vendorcode=? where v.vendorname=?"; SQLQuery query = vDao.getHibernateSession().createSQLQuery(sql); query.setParameter(0, vo.getVendorCode()); query.setParameter(1, vo.getVendorName()); int result = query.executeUpdate(); return result; }
From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java
/** * ?????/*from w w w .j av a2 s .com*/ * @param vo * @return */ public int InsetAVendor(Vendor vo) { String sql = "insert into t_vendor(vendorid,vendorname,vendorcode,accountid,address,bank,businessscope,initialevaluationdate,vendorlevel,phone" + ",reviewresult,reviewdate,taxid,reposal,property,simplename,sector,email,zipcode,license,egal,setupdate,registeredcapital,bank2,bank3,accountid2," + "accountid3,deliveryaddress,availability,trial_status,trial_comment,create_date,creater,evaluation_status," + "evaluation_comment,scale,remark,type,fax,symbol,accredit" + ") values(?,?,?,?,?,?,?,to_date(?,'YYYY:MM:DD:HH24:MI:SS'),?,?,?,to_date(?,'YYYY:MM:DD:HH24:MI:SS'),?,?," + "?,?,?,?,?,?,?,to_date(?,'YYYY:MM:DD:HH24:MI:SS'),?,?,?,?,?,?,?,?,?,to_date(?,'YYYY:MM:DD:HH24:MI:SS'),?,?,?,?,?,?,?,?,?" + ")"; // 8,12,22,32 SQLQuery query = vDao.getHibernateSession().createSQLQuery(sql); query.setParameter(0, UtilForHD.GetNowTimeForId()); query.setParameter(1, vo.getVendorName()); query.setParameter(2, vo.getVendorCode()); query.setParameter(3, vo.getAccountID()); query.setParameter(4, vo.getAddress()); query.setParameter(5, vo.getBank()); query.setParameter(6, vo.getBusinessScope()); query.setParameter(7, this.GetDate(vo.getInitialEvaluationDate())); query.setParameter(8, vo.getVendorLevel()); query.setParameter(9, vo.getPhone()); query.setParameter(10, vo.getReviewResult()); query.setParameter(11, this.GetDate(vo.getReviewDate())); query.setParameter(12, vo.getTaxID()); query.setParameter(13, vo.getReposal()); query.setParameter(14, vo.getProperty()); query.setParameter(15, vo.getSimpleName()); query.setParameter(16, vo.getSector()); query.setParameter(17, vo.getEmail()); query.setParameter(18, vo.getZipCode()); query.setParameter(19, vo.getLicense()); query.setParameter(20, vo.getEgal()); query.setParameter(21, this.GetDate(vo.getSetUpDate())); query.setParameter(22, vo.getRegisteredCapital()); query.setParameter(23, vo.getBank2()); query.setParameter(24, vo.getBank3()); query.setParameter(25, vo.getAccountID2()); query.setParameter(26, vo.getAccountID3()); query.setParameter(27, vo.getDeliveryAddress()); query.setParameter(28, vo.getAvailability()); query.setParameter(29, vo.getTrial_status()); query.setParameter(30, vo.getTrial_comment()); query.setParameter(31, this.GetDate(vo.getCreate_date())); query.setParameter(32, vo.getCreater()); query.setParameter(33, vo.getEvaluation_status()); query.setParameter(34, vo.getEvaluation_comment()); query.setParameter(35, vo.getScale()); query.setParameter(36, vo.getRemark()); query.setParameter(37, vo.getType()); query.setParameter(38, vo.getFax()); query.setParameter(39, vo.getSymbol()); query.setParameter(40, vo.getAccredit()); return query.executeUpdate(); }