Oracle Additions and deletions

Source: Internet
Author: User

Oracle Starter Case:

1. Create an entity class student and override the ToString method

 Packagecn.happy.entity; Public classStudent { PublicInteger getId () {returnID; }     Public voidsetId (Integer id) { This. ID =ID; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     PublicInteger getage () {returnAge ; }     Public voidsetage (Integer age) { This. Age =Age ; } @Override PublicString toString () {return"Student [name=" + name + ", age=" + Age + ", id=" + ID + "]"; }    PrivateString name; PrivateInteger age; PrivateInteger ID;

}

2. Importing the JAR Package

3. Create a large configuration associated small configuration

<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<! DOCTYPE hibernate-configuration Public
"-//hibernate/hibernate Configuration DTD 3.0//en"
"Http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >


<session-factory>
<property name= "Connection.driver_class" >oracle.jdbc.OracleDriver</property>
<property name= "Connection.url" >jdbc:oracle:thin: @localhost:1521:orcl</property>
<property name= "Connection.username" >scott</property>
<property name= "Connection.password" >0123</property>

<!--output all SQL statements to the console. -
<property name= "Hibernate.show_sql" >true</property>

<!--print more beautiful SQL in log and console. -
<property name= "Hibernate.format_sql" >true</property>
<!--dialect---
<property name= "Hibernate.dialect" >org.hibernate.dialect.Oracle10gDialect</property>

<property name= "Hbm2ddl.auto" >update</property>


<mapping resource= "Cn/happy/entity/student.hbm.xml"/>


</session-factory>

4. Write small configuration coding= ' utf-8 '?>

<! DOCTYPE hibernate-     mappingPublic "-//hibernate/hibernate mapping DTD 3.0//en"    "/http WWW.HIBERNATE.ORG/DTD/HIBERNATE-MAPPING-3.0.DTD "> Package  =" Cn.happy.entity ">     <  Class Name= "Student" table= "Student" >         <id name= "id" type= "int" column= "id" >         </id>         <property name= "Name" type= "string" column= "name"/>         <property name= "age" type= "Int." column= "Age"/>     </class>     

5. Tool Class

 Packagecn.happy.entity;Importorg.hibernate.Session;Importorg.hibernate.SessionFactory;Importorg.hibernate.cfg.Configuration; Public classHibernateutil {Private StaticConfiguration cfg=NewConfiguration (). Configure (); Private StaticSessionfactory factory=cfg.buildsessionfactory (); //01. Method to return to session     Public StaticSession getsession () {returnfactory.opensession (); }        //02. Close Session     Public Static voidclosesession () {getsession (). Close (); }    }

6. Test class

    //1.2 Revision Students@Test Public voidUpdatetest () {Session session=hibernateutil.getsession (); //object not tracked by context         /*Student stu=new Student ();         Stu.setid (3); Stu.setname ("Cold Rain Training Camp");*/                  //Way Two: How to use the context tracking method//retrieves a record, an entity objectStudent stu= (Student) session.load (Student.class, 3); Stu.setname ("Jin Long refueling!!!!" "); Transaction TX=session.begintransaction ();         Session.update (Stu);         Tx.commit ();         Hibernateutil.closesession (); System.out.println ("Update ok!"); }    

Oracle Additions and deletions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.