//hibernate cfg file// <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="connection.username">root</property> <property name="connection.url"> jdbc:mysql://localhost:3306/student </property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="myeclipse.connection.profile">local</property> <property name="hbm2ddl.auto">update</property> <property name="connection.password">root</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="show_sql">true</property> <mapping resource="org/savinirs/pojos/Studentreg.hbm.xml" /> </session-factory> </hibernate-configuration> // StudentBeans file// package org.savinirs.beans; import org.apache.struts.action.ActionForm; public class StudentBeans extends ActionForm { public String fname; public String lname; public String email; public String reg; public String add; public String gender; public String course; public Integer stdid; public Integer age; public String getFname() { return fname; } public void setFname(String fname) { this.fname = fname; } public String getLname() { return lname; } public void setLname(String lname) { this.lname = lname; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getReg() { return reg; } public void setReg(String reg) { this.reg = reg; } public String getAdd() { return add; } public void setAdd(String add) { this.add = add; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getCourse() { return course; } public void setCourse(String course) { this.course = course; } public Integer getStdid() { return stdid; } public void setStdid(Integer stdid) { this.stdid = stdid; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } } //Action file// package org.savinirs.action; 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 org.apache.struts.actions.MappingDispatchAction; import org.hibernate.Hibernate; import org.savinirs.beans.StudentBeans; import org.savinirs.pojos.Studentreg; import org.savinirs.util.HibernateSessionFactory; public class LoginAction extends MappingDispatchAction{ public ActionForward studentmethod(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { org.hibernate.Session hiberobj=null; try { System.out.println("hi......"); hiberobj=HibernateSessionFactory.getSessionFactory().openSession(); hiberobj.beginTransaction(); System.out.println("insertion begin"); StudentBeans obj=(StudentBeans) form; Studentreg pojoobj=new Studentreg(); pojoobj.setFname(obj.getFname()); pojoobj.setLname(obj.getLname()); pojoobj.setEmail(obj.getEmail()); pojoobj.setReg(obj.getReg()); pojoobj.setAdd(obj.getAdd()); pojoobj.setGender(obj.getGender()); pojoobj.setCourse(obj.getCourse()); pojoobj.setAge(obj.getAge()); hiberobj.save(pojoobj); hiberobj.getTransaction().commit(); System.out.println("Done"); hiberobj.close(); return mapping.findForward("sucess"); } catch (Exception e) { e.printStackTrace(); request.setAttribute("msg1","give proper details"); return mapping.findForward("failure"); // TODO: handle exception } } } //struts cnfg file// <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans > <form-bean name="StudentBeans" type="org.savinirs.beans.StudentBeans"/> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings > <action name="StudentBeans" path="/studentmethod" parameter="studentmethod" type="org.savinirs.action.LoginAction" scope="request"> <forward name="sucess" path="/sucess.jsp"/> <forward name="failure" path="/StudentPage.jsp"/> </action> </action-mappings> <message-resources parameter="org.savinirs.struts.ApplicationResources" /> </struts-config> //student registration page// <body> <form name="regForm" action="studentmethod.do" > <h3> STUDENT REGISTRATION</h3> <table align=center> <tr> <td>FIRST NAME <input type="text" name="fname" id="fname" value=""> </td> </tr> <tr> <td>LAST NAME <input type="text" name="lname" id="lname" value=""> </td> </tr> <tr> <td>EMAIL <input type="text" name="email" id="email" value=""> </td> </tr> <tr> <td>STUDENT ID <input type="text" name="studid" id="studid" value=""> </td> </tr> <tr> <td>REGISTRATION NO: <select id="reg" name="reg"><option></option> <option value="10yasca001">10yasca001</option><option value="10yasca002">10yasca002</option><option value="10yasca003">10yasca003</option><option value="10yasca004">10yasca004</option> </select> </td> </tr> <tr> <td>AGE <input type="text" name="age" id="age" value=""> </td> </tr> <tr> <td>ADDRESS <textarea rows="2" cols="20" name="add" id="add"></textarea> </td> </tr> <tr> <td>GENDER <input type="radio" name="gender" id="gender" value="male" >Male <input type="radio" name="gender" id="gender" value="female">Female </td> </tr> <tr> <td>COURSE <input type="checkbox" name="course" id="course" value="UG">UG <input type="checkbox" name="course" id="course" value="PG">PG </td> </tr> <tr> <td colspan="2">${requestScope.msg1 }</td> </tr> <tr> <td align=center> <input type="submit" value="SUMBIT" /> </td> </tr> </table> </form> </body> //student database// studentreg coloumns fname,char(40),Nullable lname,char(40),Nullable email,varchar(40),Nullable reg,varchar(20),Nullable add,varchar(30),Nullable gender,char(5),Nullable course,char(5),Nullable stdid,int(11) age,int(2),Nullable stdid primary key with auto generate.. while trying to save data in database im getting error: insertion begin Hibernate: insert into student.studentreg (fname, lname, email, reg, add, gender, course, age) values (?, ?, ?, ?, ?, ?, ?, ?) org.hibernate.exception.SQLGrammarException: could not insert: [org.savinirs.pojos.Studentreg] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638) at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250) ");
Ads