首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

不运用hibernate.cfg.xml

2013-08-04 
不使用hibernate.cfg.xmlpackage org.xiazdongimport java.util.Propertiesimport org.hibernate.Sessio

不使用hibernate.cfg.xml
package org.xiazdong;import java.util.Properties;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import org.hibernate.classic.Session;public class UserTest {public static void main(String[] args) {Properties p = new Properties();p.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");p.put("hibernate.connection.url", "jdbc:mysql:///hibernate");p.put("hibernate.connection.username", "root");p.put("hibernate.connection.password", "12345");p.put("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");p.put("hibernate.hbm2ddl.auto","update");Configuration conf = new Configuration().setProperties(p).addClass(User.class);SessionFactory sf = conf.buildSessionFactory();Session session = sf.openSession();Transaction tx = session.beginTransaction();User u = new User();u.setName("xiazdong-1");u.setAge(20);session.save(u);tx.commit();session.close();sf.close();}}

?

热点排行