大家帮帮忙..~public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
int id = Integer.parseInt(request.getParameter("id"));
SelfProjectActionForm selfProjectActionForm=(SelfProjectActionForm)form;
String labadvice=new String(selfProjectActionForm.getLabadvice().getBytes("ISO-8859-1"),"GB2312");
String tutoradvice=new String(selfProjectActionForm.getTutoradvice().getBytes("ISO-8859-1"),"GB2312");
selfDao=this.getSelfProjectDAO();
Selfproject selfproject=selfDao.getSelfProjectByID(id);
selfproject.setTutoradvice(tutoradvice);
selfproject.setLabadvice(labadvice);
try{
if(!selfDao.updateSelfProject(selfproject)){
return mapping.findForward("failure");
}else{
return mapping.findForward("success");
}
}catch(HibernateException e){
e.printStackTrace();
return mapping.findForward("failure");
}
}
其中呢 selfproject是有20个字段的,先前的A页面先插入15个字段,当时未插入的为空,
然后到现在的B页面,显示那15个字段,并提供另外2个字段的输入框,即Tutoradvice和Labadvice..
然后提交到 贴出代码的 Action里,
可以执行到else{
return mapping.findForward("success"); 也就是说selfDao.updateSelfProject(selfproject)是已经成功执行了 但是 数据库中 tutoradvice 和 labadvice仍然为空. 不知道是怎么回事呢? 好像是没有分数了 不好意思啊 麻烦大家给看看啊 拜托了......
HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
int id = Integer.parseInt(request.getParameter("id"));
SelfProjectActionForm selfProjectActionForm=(SelfProjectActionForm)form;
String labadvice=new String(selfProjectActionForm.getLabadvice().getBytes("ISO-8859-1"),"GB2312");
String tutoradvice=new String(selfProjectActionForm.getTutoradvice().getBytes("ISO-8859-1"),"GB2312");
selfDao=this.getSelfProjectDAO();
Selfproject selfproject=selfDao.getSelfProjectByID(id);
selfproject.setTutoradvice(tutoradvice);
selfproject.setLabadvice(labadvice);
try{
if(!selfDao.updateSelfProject(selfproject)){
return mapping.findForward("failure");
}else{
return mapping.findForward("success");
}
}catch(HibernateException e){
e.printStackTrace();
return mapping.findForward("failure");
}
}
其中呢 selfproject是有20个字段的,先前的A页面先插入15个字段,当时未插入的为空,
然后到现在的B页面,显示那15个字段,并提供另外2个字段的输入框,即Tutoradvice和Labadvice..
然后提交到 贴出代码的 Action里,
可以执行到else{
return mapping.findForward("success"); 也就是说selfDao.updateSelfProject(selfproject)是已经成功执行了 但是 数据库中 tutoradvice 和 labadvice仍然为空. 不知道是怎么回事呢? 好像是没有分数了 不好意思啊 麻烦大家给看看啊 拜托了......
try{Session s=HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
s.update(selfproject);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
return true;
}catch(HibernateException e){
log.fatal(e);
}
return false;
}这个代码 看着也没问题啊...还是不行啊 哭了..
@Test
public void update(){
Session session = HibernateUitl.getSessionFactory().getCurrentSession();
session.beginTransaction();
Teacher t = (Teacher) session.get(Teacher.class, 3);
t.setName("yangtb2");
session.update(t);
session.getTransaction().commit();
}
}
updateSelfProject
这个方法加上事务(如果是hibernate)
如 LeeHomWong 6楼所说的那样试!如果是jdbc的默认如果成功的话会自动提交 的
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {//创建SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();
}catch(Throwable ex){
ex.printStackTrace();
System.out.println("Initial SessionFactory creation failed.");
throw new ExceptionInInitializerError(ex);
}
}
public static final ThreadLocal<Session> tLocalsess=new ThreadLocal<Session>();
public static final ThreadLocal<Transaction> tLocaltx=new ThreadLocal<Transaction>();
//取得session
public static Session currentSession(){
Session session=(Session)tLocalsess.get();
//打开一个新的session,如果当前不可用
try{if(session==null||!session.isOpen()){
session=openSession();
tLocalsess.set(session);
}
}catch(HibernateException e){
e.printStackTrace();
}
return session;
}
//关闭session
public static void closeSession(){
Session session = (Session) tLocalsess.get();
tLocalsess.set(null);
try{if(session!=null&&session.isOpen()){
session.close();
}
}catch(HibernateException e){}
}
//开始事务
public static void beginTransaction(){
//声明Transaction类型对象x,并赋初值
Transaction tx=(Transaction)tLocaltx.get();
try{
if(tx==null){
tx=currentSession().beginTransaction();
tLocaltx.set(tx);
}
}catch(HibernateException e) {
//抛出异常
}
}
//关闭事务
public static void commitTransaction(){
Transaction tx=(Transaction) tLocaltx.get();
try{if(tx!=null&&!tx.wasCommitted()&&!tx.wasRolledBack())
tx.commit();
tLocaltx.set(null);
System.out.println("commit tx");
}catch(HibernateException e){}
}
//事务回滚
public static void rollbackTransaction(){
Transaction tx=(Transaction) tLocaltx.get();
try {
tLocaltx.set(null);
if(tx!=null&&!tx.wasCommitted()&&!tx.wasRolledBack()){
tx.rollback();
}
}catch(HibernateException e){}
}
private static Session openSession()throws HibernateException{
return getSessionFactory().openSession();
}
private static SessionFactory getSessionFactory() throws HibernateException{
return sessionFactory;
}
} 您看 有问题吗 没有的话 我在去仔细看看Hibernate教材里关于这部分的内容