Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


siya s
SQLGrammarException while trying to save data in db
0 Answer(s)      a year and 8 months 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)

");

Advertisement
View Answers

Related Tutorials/Questions & Answers:
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
Advertisements
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
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 data DAO
save data DAO  how to save data in db   package com.tcs.ignite.dao; import com.tcs.ignite.bean.User; import com.tcs.ignite.connection.Connectiondetails; import java.sql.ResultSet; import java.sql.SQLException; import
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
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 featch data form db?
how to featch data form db?  how to featch data form db?   ...(){ $.getJSON('get','act=all',function(data){ var...="thumbnail">' +'<img data-src="holder.js/300x200
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
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
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
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
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 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
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 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
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
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
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
)) { while (rs.next()) { %><option><
db
)) { while (rs.next()) { %><option><
How to get data from DB in to Text box by using Jsp & Ajax
How to get data from DB in to Text box by using Jsp & Ajax   I want to get the data from database in to text box in a jsp page by using Ajax. If I enter the letter A in the textbox it should show only those values which starts
Storing and retrieving data alongwith image in mysql db using jsp
Storing and retrieving data alongwith image in mysql db using jsp  I want to store and retrieve the whole data as shown below in mysql db. I've put... as it is really important for my project????? THIS IS MY DB Table. mysql> use
How to save data to excel with a 2.1 work sheet format without changing it?
How to save data to excel with a 2.1 work sheet format without changing it?  hi , i have done a program that allows user to inout data through jtable and save it to excel file then read it again .. the problem is , when data
How to save form data to a csv file using jquery or ajax
How to save form data to a csv file using jquery or ajax  Please let...) {// code for IE7+, Firefox, Chrome, Opera, Safari data=new XMLHttpRequest(); } else {// code for IE6, IE5 data=new ActiveXObject
how to save html form data into .csv file using only jsp.
how to save html form data into .csv file using only jsp.  Dear all, I am developing a website only using jsp and html. i need to save the form data...:\\File.xls"); wb.write(fileOut); fileOut.close(); out.println("Data is saved
How to Generate XML files from the data in DB tables?
How to Generate XML files from the data in DB tables?  HI Experts, I have a doubt. I have a table say Pest. My task is to generate XML file with all the fields in table and store it to database.Please help me.I am new to XML
How to read every cell of an excel sheet using Apache POI and insert those data into a DB?
How to read every cell of an excel sheet using Apache POI and insert those data into a DB?   i have an excel sheet, whose data in each cell has to be read and those data has to be inserted in the DB. This has to happen for all
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
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
How to download web page table data, export the table records in an excel file and save
be displayed and ask me to save the file. on clicking the save button the data should...How to download web page table data, export the table records in an excel file and save  i have a web page(.jsp) which contains the table of 4 to 5
how to check dates while retrieving data from database
how to check dates while retrieving data from database  i want to update database record based on delivery date i have tried this query but it wont work b="update deliveryorder set prtnm='"+arr[1]+"',stn='"+arr[0]+"',sbston
connection of java file to excel file and put data from excel file into oracle db
as wellas to oracle db to insert excel data into database...connection of java file to excel file and put data from excel file into oracle db  how to create button on excel sheet using java swing and how we
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."  Hi, How to get data from MYSQL Database tables on giving a "text" in a text-box in a JSP file. Ex:dept table; if we give dept_no in a text-box in JSP
DB Insert
DB Insert  How to insert XML data into a database column? Column data type is CLOB
Sorting data in a jsp using a servlet while implementing comparable - JSP-Servlet
Sorting data in a jsp using a servlet while implementing comparable  Hi Sorry for being not so clear before. I have 3 records in my database. I want to sort them according to their respective headings. Here's the code I have
Wrong parameter values while exporting data from jsp to excel
Wrong parameter values while exporting data from jsp to excel   This is a jsp report. When i export the report data to an excel, the parameter...(); out.println("Data is saved in excel file."); }catch ( Exception ex ){ } %>
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database - Java Beginners
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database  Hello Sir I want Store Corse Type that contains Two...(3,g); int i=st.executeUpdate(); JOptionPane.showMessageDialog(null,"Data
convert excel file data into different locales while converting exclile file to csv file
convert excel file data into different locales while converting exclile file to csv file   can any one provide the code for how to convert excel file data into different locales while converting exclile file to csv file
db connectivity
db connectivity  hi i am beginner in objective c lang and having knowlwgde of basic syntax of this lang and need statements that can be used to connect to sqlite. please do send me the simple example code. i am using GNUstep
DB connectivity - EJB
DB connectivity  DB connectivity
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
 

 

 

DMCA.com