RT。
抛出异常后程序就不能动啦。但是我希望查不到的时候,能够做些其他事情,比如返回写东西,告诉人家查不到什么的
谁能告诉我 或者谁有这类的代码,贴上来看看
谢谢

解决方案 »

  1.   

    Session session = sessionFac.HibernateSessionFactory.getSession();
    System.out.println("session build");
    accountInfo accInfo = new accountInfo();
    System.out.println("new accountinfo");

    session.load(accInfo,str);
    System.out.println("sessionload");

    System.out.println(accInfo.getAccandpass());
    res=accInfo.getAccandpass();
    System.out.println(res);
    if(res.equals(str)){
    accInfo.setIpadd(ip); 
    System.out.println("IP address is"+   ip);
    Transaction tran = session.beginTransaction();
    try{
    session.update(accInfo);
    tran.commit();
    }
    catch(Exception ex){
    tran.rollback();
    }
    }
    sessionFac.HibernateSessionFactory.closeSession();

    return res;
    str代表的那个字符串在数据库中是名为accandpass这个filed里面的字符串,如果有就查到了,就没问题了。如果没有就会抛出异常。我先把代码贴出来 大家看 这就去找异常,然后更帖贴chulai 
      

  2.   

    抛出的异常是Exception in thread "Thread-3" org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [po.accountInfo#12344567898]
    我数据库里只有123123456
    如果在客户端输入12344567898就会出现如上的异常提示咋办
      

  3.   

    晕,你去查一个没有的ID 记录当然会报错。这个错误时需要你通过程序来避免的,确保你在通过ID查询一条记录是这条记录的存在性,也就是说ID要正确。一般我们的做法是,先调用getAll(),查到所有的列表显示出来,然后在通过选取其中某个ID来查看某个记录的详细,这也是增删改查一般的套路