Recently I started to watch Hibernate, I found that I have to completely understand that it is still a certain time. Record the easiest way to operate the database Create Table Manager (ID Integer Primary Key Default NextVal ('Serial' :: Text) Not Null, Name Character Varying (20) Not Null, "Password" Character Varying (20)); Map file < XML Version = "1.0"?>
Public class insertdata {
.. Public static void main (String [] args) {try {SessionFactory sf = new Configuration () configure () buildSessionFactory (); Session session = sf.openSession (); Transaction tx = session.beginTransaction (); for (int i = 1; i <10; i ) {manager m = new manager (); m.setname ("Name" i); M.SetPassword ("password"); session.save (m);}
TX.comMit (); session.close ();
} Catch (HibernateException e) {e.printStackTrace ();.}}} Update data public class UpdateData {/ * delete data * / public static void main (String [] args) {try {SessionFactory sf = new Configuration () configure () .BUILDSessionFactory (); session session = sf.opensession (); transaction tx = session.begintransaction (); // string m = "name0"; manager m1 = new manager (); m1.setID (1); m1 .SetName ("Lanhuizi"); M1.SetPassword ("Nothing"); session.Update (m1);
TX.comMit (); session.close ();
} catch (hibernateException e) {system.out.println ("error");
.}} Delete data public class DeleteData {/ * delete data * / public static void main (String [] args) {try {SessionFactory sf = new Configuration () configure () buildSessionFactory (); Session session = sf.openSession ( ); Transaction tx = session.begintransaction (); // string m = "name0"; manager m1 = new manager (); m1.setId (1); session.delete (m1);
TX.comMit (); session.close ();
} catch (HibernateException E) {E.PrintStackTrace ();}}} The above is just a simple operation, and there should be a better implementation method, batch deletion, and bulk update, especially. Aircraft