| Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML | ||||
|
||||
|
|
||||
| Tutorial Categories: Ajax
| Articles
| JSP
| Bioinformatics
| Database
| Free
Books |
Hibernate
| J2EE
| J2ME
| Java
| JavaScript
| JDBC
| JMS
| Linux
| MS
Technology |
PHP
| RMI
| Web-Services
| Servlets
| Struts
| UML
|
|
||||||||||||||||||||||||||||||
|
Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs |
||||||||||||||||||||||||||||||
Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.
Copyright © 2007. All rights reserved.
Current Comments
1 comments so far (post your own) View All Comments Latest 10 Comments:Need to add Transaction statement and use createSQLQuery() instead of createQuery() method.
-----------------------------
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class DeleteHQLExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
Session sess = null;
try{
SessionFactory fact = new Configuration().configure().buildSessionFactory();
sess = fact.openSession();
String hql = "DELETE FROM INSURANCE WHERE ID = 2";
Transaction tx = sess.beginTransaction();
Query query = sess.createSQLQuery(hql);
int row = query.executeUpdate();
tx.commit();
if(row == 0){
System.out.println(" Doesn't delete any row");
}else{
System.out.println(" Deleted row " + row);
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
sess.close();
}
}
}
Posted by Sudeepta Majhee on Saturday, 12.20.08 @ 09:09am | #82996