Myeclipse整合Spring和hibernate,之后怎么配置applicationcontext.xml,我的程序整合后不能获取session 10
applicationcontext.xml文件内容(都是自动生成的,好像需要点手动添加点什么东西,但是我不会,本人菜鸟一个,请大神们帮帮忙啊!请详细的告诉我怎么改,谢谢...
applicationcontext.xml文件内容(都是自动生成的,好像需要点手动添加点什么东西,但是我不会,本人菜鸟一个,请大神们帮帮忙啊!请详细的告诉我怎么改,谢谢谢谢~~~):
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
</bean></beans>
-------------------------------------------------------
Dao(本人写连接数据库的简单的测试);
public class Dao extends HibernateDaoSupport {
public boolean select (String u,String p) {
boolean isok= false;
String hql = "from zc z where z.zhanghao = '" + u + "' and z.pwd = '" + p+"'";
List list= this.getHibernateTemplate().find(hql);----------------到这里就出现问题了!!!!!
if(list.size() > 0 && list != null) {
isok = true;
System.out.println("--------------登陆成功---------------");
}
return isok;
}
}
错误为:Exception in thread "main" java.lang.NullPointerException
at Test.Dao.select(Dao.java:13)
at Test.Login.main(Login.java:8) 展开
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
</bean></beans>
-------------------------------------------------------
Dao(本人写连接数据库的简单的测试);
public class Dao extends HibernateDaoSupport {
public boolean select (String u,String p) {
boolean isok= false;
String hql = "from zc z where z.zhanghao = '" + u + "' and z.pwd = '" + p+"'";
List list= this.getHibernateTemplate().find(hql);----------------到这里就出现问题了!!!!!
if(list.size() > 0 && list != null) {
isok = true;
System.out.println("--------------登陆成功---------------");
}
return isok;
}
}
错误为:Exception in thread "main" java.lang.NullPointerException
at Test.Dao.select(Dao.java:13)
at Test.Login.main(Login.java:8) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询