锘??xml version="1.0" encoding="utf-8" standalone="yes"?>99www免费人成精品,四季av在线一区二区三区 ,2021中文字幕一区亚洲http://www.aygfsteel.com/luopeizhong/category/44709.html闈?/description>zh-cnTue, 20 Apr 2010 06:30:57 GMTTue, 20 Apr 2010 06:30:57 GMT60絎竴涓狧ibernate渚嬪瓙http://www.aygfsteel.com/luopeizhong/news/2010/04/18/318637.htmlcartcartSun, 18 Apr 2010 02:15:00 GMThttp://www.aygfsteel.com/luopeizhong/news/2010/04/18/318637.htmlhttp://www.aygfsteel.com/luopeizhong/comments/318637.htmlhttp://www.aygfsteel.com/luopeizhong/news/2010/04/18/318637.html#Feedback0http://www.aygfsteel.com/luopeizhong/comments/commentRss/318637.htmlhttp://www.aygfsteel.com/luopeizhong/services/trackbacks/318637.html絎竴涓狧ibernate渚嬪瓙
2007-04-21 21:39

1銆佺幆澧冨噯澶?/strong>
閲囩敤鐨勬槸eclipse騫沖彴鍔犱笂J2EE鎻掍歡myeclipse鐨勯厤緗紝鏁版嵁搴撲負(fù)寰蔣鐨凷QL Server2000錛岄┍鍔ㄤ負(fù)寰蔣鐨刯tds錛屽叿浣撻厤緗涓嬶細(xì)
eclipse 3.2.0
myeclipse 5.1.1GA
Sqlserver2000+SP4
jtds1.2.jar

2銆佹暟鎹簱
鏁版嵁搴撳悕涓篽ibernate錛屽彧鏈変竴寮犺〃computer
create table computer(
       id int(11) not null primary key auto_increment,
       cpu varchar(50),
       mainboard varchar(50),
       displaycard varchar(50),
       harddisk varchar(50),
       display varchar(50),
       memory varchar(50),
       soundcard varchar(50),
       cdrom varchar(50),
       mouse varchar(50),
       keyboard varchar(50)
);


3銆佸熀紜閰嶇疆鏂囦歡
   hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                    -->
<hibernate-configuration>

<session-factory>
<property name="myeclipse.connection.profile">profile</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">xxxxx</property>
<property name="connection.driver_class">
   com.mysql.jdbc.Driver
</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="org/bwgl/sample/hibernate3/Computer.hbm.xml" />

</session-factory>

</hibernate-configuration>

    javabean :   Computer.java[鏁版嵁搴撴墍瀵瑰簲鐨刯ava綾繪枃浠禲
package com.weportal.computer;

public class Computer {
private int id;
private String cpu;
private String mainboard;
private String memory;
private String harddisk;
private String display;
private String keyboard;
private String mouse;
private String displaycard;
private String soundcard;
private String cdrom;
/*
   *鑾峰彇computer灞炴х殑get鏂規(guī)硶
   */
public int getId(){
   return id;
}
public String getCpu(){
   return cpu;
}
public String getMainboard(){
   return mainboard;
}
public String getMemory(){
   return memory;
}
public String getHarddisk(){
   return harddisk;
}
public String getDisplay(){
   return display;
}
public String getKeyboard(){
   return keyboard;
}
public String getMouse(){
   return mouse;
}
public String getDisplaycard(){
   return displaycard;
}
public String getSoundcard(){
   return soundcard;
}
public String getCdrom(){
   return cdrom;
}
/*
   * 璁劇疆computer灞炴х殑set鏂規(guī)硶闆?br />    */
public void setId(int id){
   this.id=id;
}
public void setCpu(String cpu){
   this.cpu=cpu;
}
public void setMainboard(String mainboard){
   this.mainboard=mainboard;
}
public void setMemory(String memory){
   this.memory=memory;
}
public void setHarddisk(String harddisk){
   this.harddisk=harddisk;
}
public void setDisplay(String display){
   this.display=display;
}
public void setKeyboard(String keyboard){
   this.keyboard=keyboard;
}
public void setMouse(String mouse){
   this.mouse=mouse;
}
public void setDisplaycard(String displaycard){
   this.displaycard=displaycard;
}
public void setSoundcard(String soundcard){
   this.soundcard=soundcard;
}
public void setCdrom(String cdrom){
   this.cdrom=cdrom;
}
}

Computer.hbm.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
           "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
           "
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.weportal.computer.Computer" table="computer">
   <id name="id" type="int">
    <generator class="native"/>
   </id>
   <property name="cpu"></property>
   <property name="mainboard" ></property>
   <property name="displaycard" ></property>
   <property name="harddisk" ></property>
   <property name="display"></property>
   <property name="memory"></property>
   <property name="soundcard"></property>
   <property name="cdrom"></property>
   <property name="mouse"></property>
   <property name="keyboard"></property>
</class>
</hibernate-mapping>

log4j.Properties鏂囦歡
鏂板緩涓鏂囦歡錛岃搗鍚嶄負(fù)log4j.Properties錛屽湪鏂囦歡涓坊鍔犲涓嬪唴瀹癸細(xì)
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.rootLogger=warn,stdout

4銆佹搷浣滅被鏂囦歡
    娣誨姞鏁版嵁綾籆omputerCreate.java
package com.weportal.computer;

import java.sql.SQLException;
import org.apache.log4j.PropertyConfigurator;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class ComputerCreate {
public static void main(String args[]){
   //PropertyConfigurator.configure("log4j.Properties");
  Configuration cfg=new Configuration();
    cfg.configure();
   // cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
    SessionFactory sf=cfg.buildSessionFactory();
    Session sess=sf.openSession();
    Computer pc=new Computer();
    pc.setCpu("Intel Pentuim4 2.4B GHZ");
    pc.setDisplay("LG 563LS");
    pc.setDisplaycard("NVIDA GeForce 4 MX 440");
    pc.setHarddisk("WD120JB");
    pc.setMainboard("鎶鍢?8I845PE-RZ");
    pc.setMemory("kingMax 512MBX2");
    pc.setMouse("Logitech MX 500");
    pc.setSoundcard("Creative SB Live");
    pc.setKeyboard("Logitech");
    pc.setCdrom("Sony DVD-ROM");
    sess.save(pc);
    sess.flush();   try{
    //鎻愪氦hibernate浼?xì)璇潣q炴帴鐨勭姸鎬?br />     sess.connection().commit();
   }catch(HibernateException e){
    e.printStackTrace();
   }catch(SQLException e){
    e.printStackTrace();
   }
   sess.close();
}

}

   鍙﹀錛屽熷姪浜巋ibernate鑷韓鍔熻兘錛屽彲浠ユ牴鎹?hbm.xml鏄犲皠鏂囦歡鐢熸垚鏁版嵁搴撹〃銆侱atabaseGenerate.java綾葷敤浜庡畬鎴愯繖涓鍔熻兘銆傚煎緱娉ㄦ剰鐨勬槸錛屽鏋滄暟鎹簱涓瓨鍦ㄥ悓鍚嶈〃錛宧ibernate閲囧彇鐨勬帾鏂芥槸鍏堝垹闄よ琛紝鍐嶇敓鎴愬悓鍚嶈〃錛屽洜姝わ紝濡傛灉鏁版嵁琛ㄤ腑鏈夋暟鎹紝搴旇榪涜澶囦喚
package com.weportal.computer;

import org.apache.log4j.PropertyConfigurator;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;

public class DatabaseGenerate {
public static void main(String args[]){
   //閰嶇疆log4j.Properties
   PropertyConfigurator.configure("log4j.Properties");
   //浠巋ibernate.cfg.xml涓鍏ibernate閰嶇疆鏁版嵁
   Configuration cfg=new Configuration();
   cfg.configure();
   //鎵撳紑鑷姩鍒涘緩鍜屼慨鏀規(guī)暟鎹簱璧勬簮鐨勫紑鍏?br />    cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
   SessionFactory sf=cfg.buildSessionFactory();
}
}



cart 2010-04-18 10:15 鍙戣〃璇勮
]]>
浣跨敤Spring 2.5 鍜?Hibernate 3.2 寮鍙慚VC Web紼嬪簭(鍩轟簬annotation鐗規(guī)?http://www.aygfsteel.com/luopeizhong/news/2010/04/16/318566.htmlcartcartFri, 16 Apr 2010 13:59:00 GMThttp://www.aygfsteel.com/luopeizhong/news/2010/04/16/318566.htmlhttp://www.aygfsteel.com/luopeizhong/comments/318566.htmlhttp://www.aygfsteel.com/luopeizhong/news/2010/04/16/318566.html#Feedback0http://www.aygfsteel.com/luopeizhong/comments/commentRss/318566.htmlhttp://www.aygfsteel.com/luopeizhong/services/trackbacks/318566.html闃呰鍏ㄦ枃

cart 2010-04-16 21:59 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 富民县| 兴城市| 大英县| 洞口县| 德保县| 奈曼旗| 德兴市| 沅陵县| 枝江市| 乾安县| 西充县| 乌什县| 满洲里市| 鄢陵县| 瑞丽市| 石嘴山市| 泊头市| 来安县| 金山区| 嵊泗县| 闽侯县| 扶沟县| 潼南县| 河源市| 郴州市| 凤凰县| 铜陵市| 五寨县| 策勒县| 太康县| 汽车| 剑川县| 邓州市| 星子县| 外汇| 莆田市| 嘉黎县| 丰镇市| 弋阳县| 广安市| 尚义县|