当前位置:首页 > PHP教程 > PHP总结归纳

hebernate与mysql调整

hebernate与mysql整合 1.下载mysql, 如何安装 2.开始在myeclipse 整合hebernate hebernate 需要的一些包: 配置文件:(mysql 已开启远程连接) ?xml version='1.0' encoding='utf-8'?!doctype hibernate-configuration public -//hibernate/hibernate config

hebernate与mysql整合

1.下载mysql,

如何安装

2.开始在myeclipse 整合hebernate

hebernate 需要的一些包:

配置文件:(mysql 已开启远程连接)



  	root 	jdbc:mysql://192.168.1.135:3306/solarworkflowdb?useunicode=true&characterencoding=utf8 	org.hibernate.dialect.mysqldialect 	mysqll 	solar 	com.mysql.jdbc.driver 	true 	true 	true 	org.hibernate.cache.ehcacheprovider       

配置文件2


              测试数据                                                     
                                  
        
                                      
     

实体类:

package test;

public class person {
	private int id ;
	private string full_name;
	private string last_name;
	
	public person(){}

	public person(int id, string fullname, string lastname) {
		super();
		id = id;
		full_name = fullname;
		last_name = lastname;
	}

	public int getid() {
		return id;
	}

	public void setid(int id) {
		id = id;
	}

	public string getfull_name() {
		return full_name;
	}

	public void setfull_name(string fullname) {
		full_name = fullname;
	}

	public string getlast_name() {
		return last_name;
	}

	public void setlast_name(string lastname) {
		last_name = lastname;
	}
    
	
	
}
测试类

package test;

import org.hibernate.session;
import org.hibernate.sessionfactory;
import org.hibernate.cfg.configuration;

public class testpro {

	/**
	 * @param args
	 */
	public static void main(string[] args) {
		// todo auto-generated method stub
		person p = new person();
	
		p.setfull_name("tom");
		p.setlast_name("lee");
		configuration cfg = new configuration();
		sessionfactory sf = cfg.configure().buildsessionfactory();
		
		session session = sf.opensession();
		session.begintransaction();
		session.save(p);
		session.gettransaction().commit();
		session.close();
		sf.close();
	}

}

表结构:

 

.syntaxhighlighter{padding-top:20px;padding-bottom:20px;}
【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!