2007-03-13
在Spring+Hibernate的环境中如何通过编程模式来实现数据库连接?
在Spring+Hibernate的环境中如何通过编程模式来实现数据库连接?
似乎这样可以,但是最是不能通过factory.getObject()获得SessionFactory,而是得到Null。哪里有问题?大家给看看。
public class LocalSessionFactoryBeanTest {
public static DataSource getDataSource(){
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
ds.setUrl("jdbc:microsoft:sqlserver://192.168.0.100:1433;DatabaseName=CMCS3");
ds.setUsername("sa");
ds.setPassword("developer");
return (DataSource)ds;
}
public static SessionFactory getSessionFactory(DataSource ds) {
LocalSessionFactoryBean factory = new LocalSessionFactoryBean();
Properties p = new Properties();
p.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
p.put("hibernate.show_sql", "true");
Properties p1 = new Properties();
ArrayList<String> list = new ArrayList<String>();
list.add("classpath*:com/sky/frame/domain/*.hbm.xml");
p1.put("mappingLocations", list);
factory.setDataSource(ds);
factory.setHibernateProperties(p);
return (SessionFactory)factory.getObject();
}
public static void main(String[] args){
DataSource ds = getDataSource();
SessionFactory sf = getSessionFactory(ds);
Session session = sf.openSession();
System.out.println(session.toString());
session.close();
}
似乎这样可以,但是最是不能通过factory.getObject()获得SessionFactory,而是得到Null。哪里有问题?大家给看看。
- 浏览: 82067 次
- 性别:

- 来自: 深圳

- 详细资料
搜索本博客
最新评论
-
把JBPM运用到实际项目中( ...
现在这里好冷清哦。 如果要给予JBPM,来实现一些特殊的动作,如:收回、跳签、加 ...
-- by yuanqixun -
页面“长时间”操作引起的 ...
在对帐的时候可以在页面上加一个进度条,和Server进行交互,这样就会避免问题的 ...
-- by liushoucang -
页面“长时间”操作引起的 ...
chinata 写道tomkoo 写道 在Servlet Specificati ...
-- by ufinity -
页面“长时间”操作引起的 ...
赫赫,其实这个问题很简单,很多人第一感觉采用ajax 啊,什么定期连接一下服务器 ...
-- by titanfoot -
页面“长时间”操作引起的 ...
为什么不分页显示。让用户有一个next page的过程。为什么一次性显示给用户2 ...
-- by RyanPoy






评论排行榜