大家看看我的DAOHibernate类出错了吗?public StudentInfo findStudentByNameByPwd(
String studentName, String studentPwd) {     System.out.println("DAO1");

List ul=getHibernateTemplate().find("FROM StudentInfo as WHERE studentName=? and studentPwd = ?", 
new Object[]{studentName,studentPwd});
System.out.println("DAO2");
if (ul!=null&&ul.size()>=1)
{
return (StudentInfo)ul.get(0);
}
return null;
}
为什么控制台只能输出DAO1,而且不报出异常。。怎么回事呢。。

解决方案 »

  1.   

    FROM StudentInfo as
      

  2.   

    FROM StudentInfo  WHERE studentName=? and studentPwd = ?
      

  3.   

    FROM StudentInfo as WHERE studentName=? and studentPwd = ?",  看你SQL语句是不是错了
      

  4.   

    FROM StudentInfo stu WHERE stu.studentName=? and stu.studentPwd = ?",   
      

  5.   

    "FROM StudentInfo as WHERE studentName=? and studentPwd = ?"
    改成
    "FROM StudentInfo as WHERE studentName='?' and studentPwd = '?' ",  
     
      

  6.   

    "FROM StudentInfo as WHERE studentName=? and studentPwd = ?"
    改成
    "FROM StudentInfo as WHERE as.studentName='?' and as.studentPwd = '?' ",   
      

  7.   

    public StudentInfo findStudentByNameByPwd(
    String studentName, String studentPwd) {

    String agrs[]={studentName,studentPwd};
    List ul=getHibernateTemplate().find("FROM StudentInfo as t WHERE t.studentName=? and t.studentPwd = ?",agrs );
    System.out.println("DAO2");
    if (ul!=null&&ul.size()>=1)
    {
    return (StudentInfo)ul.get(0);
    }
    return null;
    }这是修改之后的代码。。可是结果还是一样,控制台不输出错误。。只能输出DAO1。。纠结了好久啊。。
      

  8.   

    "FROM StudentInfo as WHERE studentName=? and studentPwd = ?"
    改成
    "FROM StudentInfo as WHERE as.studentName='?' and as.studentPwd = '?' ",
    或 
    "FROM StudentInfo  WHERE studentName=? and studentPwd = ?"
      

  9.   

    你好!我根据你的意见改过之后的代码是:
    public StudentInfo findStudentByNameByPwd(
    String studentName, String studentPwd) {

    System.out.println("DAO1");

    String agrs[]={studentName,studentPwd};

    System.out.println("DAO2");
    List ul=getHibernateTemplate().find("FROM StudentInfo as t WHERE t.studentName='?' and t.studentPwd = '?'",agrs );
    System.out.println("DAO3");
    if (ul!=null&&ul.size()>=1)
    {
    return (StudentInfo)ul.get(0);
    }
    return null;
    }控制台输出了java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!的错误还希望你多多指点下。。
      

  10.   

    "FROM StudentInfo as WHERE studentName=? and studentPwd = ?"
    改成
    "FROM StudentInfo aa WHERE aa.studentName='?' and aa.studentPwd = '?' "  as 是不行的
    或  
    "FROM StudentInfo WHERE studentName=? and studentPwd = ?"
      

  11.   


    你好!我根据你的意见改过之后的代码是:
    public StudentInfo findStudentByNameByPwd(
    String studentName, String studentPwd) {System.out.println("DAO1");String agrs[]={studentName,studentPwd}; System.out.println("DAO2");
    List ul=getHibernateTemplate().find("FROM StudentInfo as t WHERE t.studentName='?' and t.studentPwd = '?'",agrs ); 
    System.out.println("DAO3");
    if (ul!=null&&ul.size()>=1)
    {
    return (StudentInfo)ul.get(0);
    }
    return null;
    }控制台输出了java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!的错误还希望你多多指点下。。
      

  12.   


    try{
        List ul=getHibernateTemplate().find("FROM StudentInfo as t WHERE t.studentName=? and t.studentPwd = ?",agrs ); 
    }catch(HibernateException e){
        System.out.println(e.getMessage());
    }
    先这样捕捉下异常!
      

  13.   

    你好,我根据你的办法试了,控制台是什么错误都没有。。
    修改后代码是:
    public StudentInfo findStudentByNameByPwd(
    String studentName, String studentPwd) {

    System.out.println("DAO1");

    String agrs[]={studentName,studentPwd};

    System.out.println("DAO2");
    try{
    List ul=getHibernateTemplate().find("FROM StudentInfo t WHERE t.studentName=? and t.studentPwd =?",agrs);
    System.out.println("DAO3");
    }catch(HibernateException e){
      System.out.println(e.getMessage());
    }
    return null;
    }
      

  14.   


    真的是什么都没有。。提交到action处理后,输入正确的用户名和密码之后页面变成空白的页面。。就执行到数据库查询字段的那里就没有输出了。。很是郁闷啊。
      

  15.   

    System.out.println(studentName+","String studentPwd);
    try{
    List ul=getHibernateTemplate().find("FROM StudentInfo t WHERE t.studentName=? and t.studentPwd =?",agrs); 
    System.out.println("DAO3");
    }catch(Exception e){
    System.out.println(e.getMessage());
    }try{
    if (ul!=null&&ul.size()>=1)
    {
    System.out.println("DAO4");
    return (StudentInfo)ul.get(0);
    }
    }catch(Exception e){
        System.out.println("if 异常"+e.getMessage());
    }
    目的是判断参数是否已经正确传入,如果正确传入了,有异常也应该就是在这两个地方的了(根据是否有DAO3和DAO4的输出)
      

  16.   

    System.out.println(studentName+","+studentPwd);
      

  17.   


    在外面套个try catch吧(find可能抛出了某个RuntimeException) 可能是调用这个函数的代码捕捉到了异常却没有任何处理(可能你catch的是Throwble这种级别的异常)
      

  18.   

    FROM StudentInfo stu WHERE stu.studentName=? and stu.studentPwd = ?", 
      

  19.   


    你好,你看看根据你的指导后修改的代码:
    public StudentInfo findStudentByNameAndByPass(
    String studentName, String studentPwd) {

        System.out.println(studentName+studentPwd);
        
    List ul=getHibernateTemplate()
    .find("from StudentInfo t where t.studentName=? and t.studentPwd = ? " , 
    new String[]{studentName,studentPwd});

    System.out.println("DAO3");

    try{ if (ul!=null&&ul.size()>=1)
    {
    System.out.println("DAO4"); return (StudentInfo)ul.get(0);
    }
         }catch(Exception e){
          
      System.out.println("if 异常"+e.getMessage());
    }
    return null;
    }是哪里错了吗?控制台能输出的是我输入的与数据库对应的名字和密码,但是没有DAO3和DAO4的输出,也没有任何异常。。为什么能传入参数了,还是不能进去List ul=getHibernateTemplate()
    .find("from StudentInfo t where t.studentName=? and t.studentPwd = ? " ,这里呢,你觉得会不会是我其他的什么配置有问题了。。