Persisting data in Google data store

Previous Google App Engine tutorials:

Google App Engine Plugin installation in Eclipse

Google App Engine Application creation in Eclipse

Google App Engine Project Deployment

Write one registration.jsp form file.

<form action="/RegistrationServlet" method="post"> <center> <H3 bgcolor="red"> <font size="6"> **STUDENT DETAILS** </font> </H3> <table align="center"> <tr> <td><b>First Name:*</b></td> <td><input type="text" name="firstname" size=15></td> </tr> <tr> <td><b>Last Name:*</b></td> <td><input type="text" name="lastname" size=15></td> </tr> <tr> <td><b>Mobile No:*</b></td> <td><input type="text" name="mobileno" size=15></td> </tr> <tr> <td><b>Mail Account:*</b></td> <td><input type="text" name="mail" size=15></td> </tr> <tr> <td><b>FeeAmount:*</b></td> <td><input name="feeAmount" type="feeAmount" size=15> </td> </tr> <tr> <td><b>Course:*</b></td> <td><input name="course" type="course" size=15></td> </tr> </table> <td><br> <br> <input type="submit" name="Register" value="Submit"></td> <h4> <a href="../index.html">Back</a> </h4> </center> </form>

Write one class Entitymanager

public final class EntityManagerFactory { private static final javax.persistence. EntityManagerFactory emfInstance = Persistence .createEntityManagerFactory("datastore"); private EntityManagerFactory() { } public static javax.persistence.EntityManagerFactory get() { return emfInstance; } }

Write servlet class

import; import javax.persistence.EntityManager; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.gk.pojo.NewStudent; import com.gk.pojo.EntityManagerFactory; @SuppressWarnings("serial") public class RegistrationServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse resp) throws IOException { String firstname = request.getParameter("firstname"); String lastname = request.getParameter("lastname"); String mobileno = request.getParameter("mobileno"); String mail = request.getParameter("mail"); String feeAmount = request.getParameter("feeAmount"); String course = request.getParameter("course"); EntityManager em = EntityManagerFactory.get(). createEntityManager(); em.getTransaction().begin(); NewStudent stud = new NewStudent(); stud.setFirstname(firstname); stud.setLastname(lastname); stud.setMobileno(mobileno); stud.setMail(mail); stud.setFeeAmount(feeAmount); stud.setCourse(course); em.persist(stud); em.getTransaction().commit(); resp.getWriter().print("Successfully Registerd"); } }

Initialize mapping servlet web.xml

<servlet> <servlet-name>RegistrationServlet</servlet-name> <servlet-class> </servlet-class> </servlet> <servlet-mapping> <servlet-name>RegistrationServlet</servlet-name> <url-pattern>/RegistrationServlet/*</url-pattern> </servlet-mapping>

Write one pojo class for table creation..

@Entity @Table(name = "student1") public class NewStudent { @Id @GeneratedValue private int id; @Column private String firstname; @Column private String lastname; private String mobileno; private String mail; private String feeAmount; private String course; public int getId() { return id; } public void setId(int id) { = id; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getMobileno() { return mobileno; } public void setMobileno(String mobileno) { this.mobileno = mobileno; } public String getMail() { return mail; } public void setMail(String mail) { this.mail = mail; } public String getFeeAmount() { return feeAmount; } public void setFeeAmount(String feeAmount) { this.feeAmount = feeAmount; } public String getCourse() { return course; } public void setCourse(String course) { this.course = course; } }

Add this pojo class in persist.xml

<?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns="" xmlns:xsi="" xsi:schemaLocation="" version="1.0"> <persistence-unit name="datastore"> <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider> <class>com.gk.pojo.NewStudent</class> <properties> <property name="datanucleus.NontransactionalRead" value="true"/> <property name="datanucleus.NontransactionalWrite" value="true"/> <property name="datanucleus.ConnectionURL" value="appengine"/> </properties> </persistence-unit> </persistence>

Finally run the project →copy localhost address from the →console paste in browser.

run the project

Student Details

Enter details then submit..

Student Details pass the values

Click on submit..

Sucessfully Registerd

Copy admin url fom the console.. paste in browser

Copy the admin url

You will get output with table name.. click on

List Entities

Datastore viewer

Table colums details is shown ..

Datastore viewer list

Table creation and insert the values is over……..

HTML Comment Box is loading comments...