Insert Method
CopyCode The Code is as follows: public void insert (Object O) {session = hibernatesessionfactory. currentsession (); transaction T = session. begintransaction (); Session. save (o); T. commit (); hibernatesessionfactory. closssession ();}
Delete Method Copy codeThe Code is as follows: public void Delete (Object o, serializable ID) {session = hibernatesessionfactory. currentsession (): Transaction T = session. begintransaction (); object o = session. get (O. class, ID); If (o! = NULL) {session. Delete (o);} t. Commit (); hibernatesessionfactory. closssession ();}
Update Method Copy codeThe Code is as follows: public void Update (Object o, serializable ID) {session = hibernatesessionfactory. currentsession (); transaction T = session. begintransaction (); Session. update (O, ID); T. commit (); hibernatesessionfactory. closssession ();}
General select method based on hql Copy codeThe Code is as follows: public arraylist select (string SQL) {session = hibernatesessionfactory. currentsession (); query = createquery (SQL); List list = query. list (); hibernatesessionfactory. closssession (); Return (arraylist) list ;}
SQL-based general select Method Copy codeThe Code is as follows: public arraylist select (string SQL) throws exception {session = hibernatesessionfactory. currentsession (); connection con = session. connection (); preparedstatement pstmt = con. preparedstatement (SQL); resultset rs = pstmt.exe cutequery (); resultsetmetadata rsmd = Rs. getmetadata (); hashtable ht = NULL; arraylist array = new arraylist (); While (RS. next () {ht = new hashtable (); For (INT I = 0; I <rsmd. getcolumncount (); I ++) {ht. put (rsmd. getcolumnname (I + 1), RS. getObject (I + 1);} array. add (HT);} hibernatesessionfactory. closssession (); Return array ;}