INSERT
String
sname=request.getParameter("sname");
SessionFactory sdf=new
Configuration().configure().buildSessionFactory();
Session s=sdf.openSession();
Transaction tr=s.beginTransaction();
Hyper obj=new Hyper(1,fname,sname);
s.save(obj);
tr.commit();
s.close();
out.println("DATA INSERTED....");
SELECT
SessionFactory sdf=new
Configuration().configure().buildSessionFactory();
Session session=sdf.openSession();
Transaction tx=session.beginTransaction();
List employees = session.createQuery("FROM Hyper").list();
for(int i=0;i<employees.size();i++)
{
Hyper hyper=(Hyper) employees.get(i);
out.println(hyper.getId());
out.println(hyper.getFname());
out.println(hyper.getSname());
out.println("</br>");
// out.println(employees.get(i));
}
UPDATE:
String
fname=request.getParameter("fname");
String sname=request.getParameter("sname");
String upd=request.getParameter("upd");
SessionFactory factory1 = new Configuration().configure().buildSessionFactory();
Session session=factory1.openSession();
Transaction tx=session.beginTransaction();
String hql = "UPDATE Hyper set fname = :temp ,sname = :temp1
" +
"WHERE id = :id";
out.println(fname);
out.println(sname);
out.println(upd);
Query query = session.createQuery(hql);
query.setParameter("temp",fname);
query.setParameter("temp1",sname);
query.setParameter("id",Integer.parseInt(upd));
int result = query.executeUpdate();
out.println("Rows affected: " + result);
tx.commit();
session.close();
DELETE
String delid=request.getParameter("del");
SessionFactory factory1 = new Configuration().configure().buildSessionFactory();
Session session=factory1.openSession();
Transaction tx=session.beginTransaction();
String hql = "DELETE FROM Hyper " +
"WHERE id = :id";
Query query = session.createQuery(hql);
query.setParameter("id",
Integer.parseInt(delid));
int result = query.executeUpdate();
//Regis r=new (Regis) result;
out.println("Rows DELETED: " + result);
//session.save(query);
tx.commit();
session.close();
TO GET MAX ID
Criteria criteria = s.createCriteria(Datahandler.class)
.setProjection(Projections.max("id"));
Integer maxid = (Integer)criteria.uniqueResult()+1;
Transaction tr=s.beginTransaction();
TO GET MAX ID
Criteria criteria = s.createCriteria(Datahandler.class)
.setProjection(Projections.max("id"));
Integer maxid = (Integer)criteria.uniqueResult()+1;
Transaction tr=s.beginTransaction();
No comments:
Post a Comment