About Hibernate Little Experience

xiaoxiao2021-03-06  121

Source: http://blog.9cbs.net/nihilism/ Recently I started to watch Hibernate, I found that it is very important to completely understand that it is still a certain day.

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"?> manager_id_serial private private constrained Insert data import net.sf.hibernate. *; import net.sf.hibernate .cfg. *; public class insertdata {public static void main (string [] args) {try {sessionFactory sf =

New configure (). CONFIGURE (). BuildSessionFactory (); session session = sf.opensesis (); 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 (hibernateExcection) { 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 (); SES Sion.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 ();

转载请注明原文地址:https://www.9cbs.com/read-99751.html

New Post(0)