Home Answers Viewqa Hibernate SQLGrammarException while trying to save data in db

 
 


siya s
SQLGrammarException while trying to save data in db
0 Answer(s)      5 months and 4 days ago
Posted in : Hibernate

//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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="fname" id="fname" value="">
   </td>
    </tr>
     <tr>
    <td>LAST NAME   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="lname" id="lname" value="">
   </td>
    </tr>
     <tr>
    <td>EMAIL    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="email" id="email" value="">
   </td>
    </tr>
    <tr>
    <td>STUDENT ID   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="studid" id="studid" value="">
   </td>
    </tr>
     <tr>
   <td>REGISTRATION NO: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   <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   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="age" id="age" value="">
   </td>
    </tr>
     <tr>
    <td>ADDRESS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <textarea rows="2" cols="20" name="add" id="add"></textarea>
   </td>
    </tr>
    <tr>
    <td>GENDER &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <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)

");
View Answers









Related Pages:
SQLGrammarException while trying to save data in db
SQLGrammarException while trying to save data in db  //hibernate cfg file// <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch... sorab"; res=stat.executeQuery(ss); while(res.next()) { jcb.addItem...,"connected to database"); stat=con.createStatement(); String ss="select name from data
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch... sorab"; res=stat.executeQuery(ss); while(res.next()) { jcb.addItem...,"connected to database"); stat=con.createStatement(); String ss="select name from data
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch... sorab"; res=stat.executeQuery(ss); while(res.next()) { jcb.addItem...,"connected to database"); stat=con.createStatement(); String ss="select name from data
db
)) { while (rs.next()) { %><option><
db
)) { while (rs.next()) { %><option><
JSP,DB
(); ResultSet rs=st.executeQuery("select * from data where id=1"); Hashtable table=new Hashtable(); int i=0; while(rs.next...(); String str; Iterator itr = set.iterator(); while (itr.hasNext
no data in db
no data in db  Using the example in "Networking/web-services-database.shtml" managed to do everything as shown above but there is no data in the database. the result is "record inserted". where can the error
save switch data into database - Java Beginners
save switch data into database  switch(menu) { case 1://add a student System.out.print("Enter student ID: "); int ID = scan.nextInt...; break; default: System.out.println("Invalid Entry!"); } } while (!quit
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database...="multipart/form-data" ACTION="upload.jsp" METHOD=POST> <br><br><
JSP,DB,SERVLET
* from data where name='"+name+"'"); while(rs.next()) { data =":"+Integer.toString...JSP,DB,SERVLET  hi thank you for your reply.With this code i can insert the data successfully into database but once i give submit button
JSP,DB,SERVLET
name='"+name+"'"); while(rs.next()) { data =":"+Integer.toString(rs.getInt("age...JSP,DB,SERVLET  hi thank you for your reply.With this code i can insert the data successfully into database but In ajax.jsp once i give the name
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
SHOWING ERROR CODE 1064 WHILE TRYING TO EXECUTE PROCEDURE
SHOWING ERROR CODE 1064 WHILE TRYING TO EXECUTE PROCEDURE  I AM TRYING A SP BUT IT IS NOT SAVING AND WORKING.DOES THE STORED PROCEDURE WORK PARTLY... ARE WORKING PROPERLY. BUT WHEN I AM TRYING TO EXECUTE THEM INSIDE
retrieving from db - JSP-Servlet
retrieving from db  hello' I am trying to write my first application connecting to the database. I have found some code but i am getting...; Hi Retrive value from database Retrive data from
JAVA DB connenting Office access..
JAVA DB connenting Office access..  hai friends....iam shackir.. i...(SQLException sqe){ System.out.println("SQl error from retrieve data... the query rs=st.executeQuery(sql); while(rs.next
java connecting to oracle db - JDBC
java connecting to oracle db  how to connect oracle data base with java application?  Hi Friend, Follow these steps: 1) Import... rs = sql_stmt.executeQuery("SELECT * from student"); String str = ""; while
How to save data - Swing AWT
How to save data  Hi, I have a problem about how to save data ,but first before data save to dababase, data must view in jLisit or Jtable... save data from jList and Jtable(in jList or jTable data will be many).Thank's
I am trying to create domains for column attributes of my data dictionary?
I am trying to create domains for column attributes of my data dictionary?  Please provide me with the best possible solution. I already have the fields and there data types in a table and then the field values in another table
How to save database data into excelsheet using hibernate
How to save database data into excelsheet using hibernate  How to save database data into excelsheet using hibernate
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password  Hi, I need the functionality in JSP to encrypt the password while inserting into DB and need decrypt logic while
after entering details in reg page,n enter the submit button,how can v store the data in db, n hw can v retrive the data frm db in jsp
the data in db, n hw can v retrive the data frm db in jsp  i ve creted... the submit button,how can v store the data in db, n hw can v retrive the data frm db(m developing new website,so it doesn't ve any data)... bt after storing data
different output trying to execute same java code
different output trying to execute same java code  i am using net...(); JOptionPane.showMessageDialog(null, "portList :"+portList.hasMoreElements()); while... there is different output trying to execute same java code
different output trying to execute same java code
different output trying to execute same java code  i am using net... :"+portList.hasMoreElements()); while (portList.hasMoreElements()) { portId... = new byte[20]; try { while (inputStream.available() > 0
different output trying to execute same java code
different output trying to execute same java code  i am using net... :"+portList.hasMoreElements()); while (portList.hasMoreElements()) { portId... = new byte[20]; try { while (inputStream.available() > 0
help me in inserting data into db using hibernate
help me in inserting data into db using hibernate  How to insert data into dependent tables through hybernate   Hi Friend, Please visit the following link: http://www.roseindia.net/hibernate/insert-data-database.shtml
To save table format data in pdf/excel in jsp
To save table format data in pdf/excel in jsp  Hello, I am doing web... table. So my question is ,I want so save this html format data in pdf/excel format... can save html table data in pdf/excel format.Your inputs are valuable to me
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password  Hi, i encrypt password and stored in to DB.but i dont know decrypt that password.plz send the code.in your site link
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please help me again ,my problem right know is how to read data from txt file then data save to database from JButton.Please give me a tutorial and source code
where is my sqlite data files(.db) will be saved?
where is my sqlite data files(.db) will be saved?  Hi, i am using SQLite with JDBC in Netbeans 7.1.1 for my project. So far, i am dealing... of SQLite will be stored in my computer? Also whether my .jar file will include the db
How to create d db for upload files using bolb i m followin dat upload file in db tutorial
How to create d db for upload files using bolb i m followin dat upload file in db tutorial  How to create d db for upload files using bolb i m followin dat upload file in db tutorial   Create a table named 'file
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening... and save this amount until he changes it again. Thank You
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening... and save this amount until he changes it again. Thank You
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening... and save this amount until he changes it again. Thank You
How can we save a data list in jsf?
How can we save a data list in jsf?  I have a code in jsf that fires a query in Data Base each time it is called, i have added a validation check... it is called again. I tried using save State but it did not help as other functions got
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve... that data will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u plz tel me the code in detail.n i thk it shud b written in jdbc
Read data from Excel and insert in to DB and export data from DB to Excel
Read data from Excel and insert in to DB and export data from DB to Excel  Read data from Excel and insert in to DB and export data from DB to Excel Hi, I need to read the data from excel and I need to insert the same in to DB
ZF Data Update in DB
= new Application_Form_Book(); $form->submit->setLabel('Save'...;   Output: Now make necessary changes and click the save button
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi, i have created... register his details,(for ex,username,password,dob,gender) 1.how that data will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u
about db - Struts
About DB in Struts  I have one problem about database. i am using netbeans serveri glassfish. so which is the data source struts config file should be? Please help me
save excel file with save and open dilog box
save excel file with save and open dilog box  following is my jsp code it is working correct.. i want to save excel file throgh jsp bt not by hard...");) user should have freedom to save the file in any location so plz give me
ERRor in executing DB program
ERRor in executing DB program  While executing following code an Error was generated.can any one help me for this. LiveDB liveDBObj = DataSourceFactory.getLiveDBInstance(); PreparedStatement pstmt=null; String qry=""; qry
While and do-while
While and do-while       Nested classes Here is another advantage of the Java, object... data, including private fields and methods. Inner classes may access static data
Server DB connection - JDBC
Server DB connection  Hello Guys I want to connect two databases at the same time but it looks like the java is only picking up the second database... to transfer the data from my localhost database to the database on the server. I have
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB... and textbox2? into MYSQL DB
db error - Java Beginners
db error  Hi, how to insert text area content into database...://192.168.10.126/"; String db = "roseindia"; String driver = "com.mysql.jdbc.Driver...(driver); con = DriverManager.getConnection(url+db, user, pass
web page altering while displaying servlet response
web page altering while displaying servlet response  in my application one index.jsp and one servlet is there and the servlet contains some db code... for this im using <%=request.getAttribute("data")%> this code and in servlet
Java DB
Java DB       Java DB is an open source Apache Derby database supported by Sun. Java DB is completely... by the developer. It is also useful for client server mode.   Java Data Objects (JDO
JSP,DB,SERVLET
JSP,DB,SERVLET  I have a jsp page called page1.jsp with 3 text fields name,phone ,city.i populated these datas into a database table through servlet...; <HEAD> <TITLE>insert data using prepared statement <BODY

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.