大家好,我的ssh集成时,不发sql语句,我的代码如下:
spring配置文件
--------------------------------------------
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="000000"></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.MySQLDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/dgj/hibernate/User.hbm.xml</value></list>
</property></bean>
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
      <ref local="sessionFactory" />
    </property>
  </bean>

<bean id="userDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<list>
<ref local="userDAO" />
</list>
</property>
<property name="transactionAttributes">
<props>

<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean> <bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- dao -->
<bean id="userDAO"
    class="com.dgj.dao.hibernate.UserDAOImpl">
    <property name="sessionFactory">
      <ref local="sessionFactory" />
    </property>
 </bean>
<!-- Action  -->
<bean name="/login" class="com.dgj.struts.action.LoginAction" scope="prototype">
<property name="userDAO">
<ref local="userDAO"/>
</property>
</bean>dao的实现类:
-----------------------------------------------------
private String hql = "from User u where u.name=?" +
"and u.password=?";
private String hql1 = "from User u where u.name=?";
protected void initDao(){

}
public User getUser(String username) { List ret = null;
Iterator it = null;

try{
ret = this.getHibernateTemplate().find(hql,username);
it = ret.iterator();
return (User)it.next();
}catch (Exception e){
log.error(e.getMessage());
return null;
}
}
struts的Action核心代码:
---------------------------------------
private UserDAO userDAO;
public UserDAO getUserDAO() {
return userDAO;
} public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
} public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm logForm = (LoginForm) form;
String username = logForm.getName();
ActionForward af = null;

String tmp = null;
User u = this.getUserDAO().getUser(username);
if(u!=null){
tmp = (String)request.getSession().getAttribute("name");
if(tmp == null){
request.getSession().setAttribute("name", username);
}else{
request.getSession().removeAttribute("name");
request.getSession().setAttribute("name", username);
}
af = mapping.findForward("login");
}else{
request.setAttribute("error", "登陆失败请输入正确的用户名和密码");
af = mapping.findForward("error");
}
return af;
}希望大家给予解决,谢谢

解决方案 »

  1.   

    集成产品还发什么SQL呀! <property name="hibernate.show_sql">true</property>
      

  2.   

     看下我的
    <property name="hibernateProperties">
             <props>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.dialect">
                   org.hibernate.dialect.Oracle9Dialect
                </prop>
             </props>
          </property>
      

  3.   

    <property name="hibernate.show_sql">true </property> 
      

  4.   

    呵呵 我用的是MySQL不是Oracle不能像你那样弄啊!
      

  5.   

    <property name="hibernate.show_sql">true </property> 这样是可以的!!
      

  6.   

    不好意思可能是我表述的不正确  不发sql的原因是根本就没有对数据库进行操作!  怀疑是dao注入的时候出错!
      

  7.   

    在控制台下点下Opent Console旁边的小三角形按钮,然后选择Java Statck Trace Console
      

  8.   

    谢谢 各位  我已经用log4j检查出来错误了  是一个hql语句出现了问题!