1和0都是什么概念?假设说1是成功,0是失败。那么: public Integer addRe(Re re) {
try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
session.saveOrUpdate(re);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
if (tx != null) {
tx.rollback();
return 1;
} else {
return 0;
}
} finally {
if (session != null) {
session.close();
}
}
}你在每次调用这个方法的时候都用一个Integer类型的对象接一下,看看能不能接到值。
try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
session.saveOrUpdate(re);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
if (tx != null) {
tx.rollback();
return 1;
} else {
return 0;
}
} finally {
if (session != null) {
session.close();
}
}
}你在每次调用这个方法的时候都用一个Integer类型的对象接一下,看看能不能接到值。
解决方案 »
- 如何实现大量TCP/UDP数据包的 解析处理?
- 请问大家通过hibernate逆向oracle的Timestamp字段怎么变成String了啊?
- trails是个好东西,研究一下?
- 高手请进,关于Tomcat+Jsp+Eclipse链接mysql数据库
- 哪位仁兄有下载Jboss4.0的有效网址,提供就有分!谢谢
- 求教JNDI问题
- 在JNDI的哪里定义IP地址啊,
- 如何从ip包中获取并修改相关信息!急急急!
- 我在eclipse上运行的WEB项目,在tomcat的webapps里没有
- 链接多数据库
- 有类似于ecshop(php)这样比较专业而开源的购物/网店J2ee程序吗?
- 这个程序该怎么实现?请教!
Integer num = 0;
try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
session.saveOrUpdate(re);
tx.commit();
num = 1;
} catch (Exception e) {
e.printStackTrace();
if (tx != null) {
tx.rollback();
}
} finally {
if (session != null) {
session.close();
}
return num;
}
}
方法为什么一定要写成Integer ? int 不行么? 我是这样写的
public int register(TblUser item){
Session session = HibernateSessionFactory.getSession() ;
Transaction tx = null ;
try {
tx = session.beginTransaction();
session.save(item);
tx.commit();
session.createQuery("select user.uid from TblUser user where user.uname = '"+item.getUname()+"'");
} catch (HibernateException e) {
// TODO Auto-generated catch block
if(tx != null){
tx.rollback();
return 0 ;
}
e.printStackTrace();
}finally{
session.close();
}
return 1 ;
}
public int register(TblUser item){
Session session = HibernateSessionFactory.getSession() ;
Transaction tx = null ;
try {
tx = session.beginTransaction();
session.save(item);
tx.commit();
session.createQuery("select user.uid from TblUser user where user.uname = '"+item.getUname()+"'");
} catch (HibernateException e) {
// TODO Auto-generated catch block
if(tx != null){
tx.rollback();
return 0 ;
}
e.printStackTrace();
}finally{
session.close();
}
return 1 ;
}
Session session = HibernateSessionFactory.getSession() ;
Transaction tx = null ;
try {
tx = session.beginTransaction();
session.save(item);
tx.commit();
session.createQuery("");我希望你能在Spring中进行dao层的配置.
这里的做法我认为是直接抛一个自定义的注册失败异常,在外面在捕获,凯不是更好一点