Note that there are some explanatory texts on larger screens.

plurals
  1. POI want to insert a value in database
    primarykey
    data
    text
    <p>I can't insert the value into database,but my coding is right.In my coding I can't save the session.I can't fix the bug. Plz help me fix the bug. Cadd.java</p> <pre><code>package controller; import com.mycompany.strutsfinal.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ActionContext; import java.util.Map; import java.util.regex.Pattern; import org.apache.struts2.ServletActionContext; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; /** * * @author joshiba */ public class Cadd extends ActionSupport { public SessionFactory factory; private String custname; private String custaddr; private static java.sql.Timestamp getCurrentTimeStamp() { java.util.Date today = new java.util.Date(); return new java.sql.Timestamp(today.getTime()); } @Override public String execute() { HttpServletRequest request=(HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); String Custname = request.getParameter("cusname"); String Custaddr = request.getParameter("cusaddrs") Session session=null; session = NewHibernateUtil.getSessionFactory().openSession(); Transaction tx = null; Integer cus=null; try{ tx = session.beginTransaction(); Customer cust12id = new Customer("custname","custaddr",0,getCurrentTimeStamp(),null,null); session.save(cust12id); Customer c=new Customer(); addActionMessage("inserted successfully"); tx.commit(); if(cus==null) addActionMessage("inserted successfully"); else addActionMessage("insert not successfully"); return "success"; }catch (HibernateException e) { if (tx!=null) tx.rollback(); e.printStackTrace(); }finally { session.close(); } return "success"; } /** * @return the custname */ public String getCustname() { return custname; } /** * @param custname the custname to set */ public void setCustname(String custname) { this.custname = custname; } /** * @return the custaddr */ public String getCustaddr() { return custaddr; } /** * @param custaddr the custaddr to set */ public void setCustaddr(String custaddr) { this.custaddr = custaddr; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload