title: how to to retrive data in jsp from MySQL using Liferay?
body: <p>I want to retrieve data from and insert data in mysql.</p>
  
  <p>I m providing 3 file one java file and two jsp file <code>edit.jsp</code> and <code>view.jsp</code> to edit and view the data respectively.</p>
  
  <p>I have created table using <code>ServiceBuilder</code>, I have put my <code>portal-ext.properties</code> in classes folder, tell me is this the perfect method? m I doing it the correct way?</p>
  
  <p>I want to first insert data and then I want to retrieve data from database.</p>
  
  <ol>
  <li><p>I m inserting data through the following jsp file - <code>edit.jsp</code></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %&gt;
  
  &lt;jsp:useBean class="java.lang.String" id="addNameURL" scope="request" /&gt;
  &lt;jsp:useBean class="java.lang.String" id="area" scope="request"/&gt;
  &lt;jsp:useBean class="java.lang.String" id="email" scope="request"/&gt;
  &lt;jsp:useBean class="java.lang.String" id="subject" scope="request"/&gt;
  &lt;jsp:useBean class="java.lang.String" id="compnay" scope="request"/&gt;
  &lt;jsp:useBean class="java.lang.String" id="designation" scope="request"/&gt;
  
  &lt;portlet:defineObjects /&gt;
  
  &lt;form id="&lt;portlet:namespace /&gt;helloForm" action="&lt;%= addNameURL %&gt;"method="post"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;Subject:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="subject"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
              Write Your Testimonial
              &lt;/td&gt;
              &lt;td&gt;&lt;textarea name ="area"&gt;&lt;/textarea&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Name:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="username"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Email:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="email"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Company:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="company"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Designation:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="designation"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
      &lt;input type="submit" id="nameButton" title="Submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre></li>
  <li><p>I have written my insertion logic in following java file - <code>Testimonial1</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.liferay.portlet;
  
  import java.io.IOException;
  import javax.portlet.ActionRequest;
  import javax.portlet.ActionResponse;
  import javax.portlet.GenericPortlet;
  import javax.portlet.PortletException;
  import javax.portlet.PortletMode;
  import javax.portlet.PortletPreferences;
  import javax.portlet.PortletRequestDispatcher;
  import javax.portlet.PortletURL;
  import javax.portlet.RenderRequest;
  import javax.portlet.RenderResponse;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import com.liferay.counter.service.CounterLocalServiceUtil;
  import com.liferay.portal.kernel.exception.SystemException;
  import com.liferay.portlet.model.testimonial;
  import com.liferay.portlet.service.testimonialLocalServiceUtil;
  
  public class Testimonial1 extends GenericPortlet {
  
      public void init()throws PortletException 
      {
          editJSP = getInitParameter("edit-jsp");
          viewJSP = getInitParameter("view-jsp");
      }
  
      public void doEdit(RenderRequest renderRequest,RenderResponse renderResponse)
              throws  IOException, PortletException 
      {
          renderResponse.setContentType("text/html");
          PortletURL addNameURL = renderResponse.createActionURL();
          addNameURL.setParameter("addName", "addName");
          renderRequest.setAttribute("addNameURL", addNameURL.toString());
          include(editJSP, renderRequest, renderResponse);
      }
  
      public void doView(RenderRequest renderRequest,RenderResponse renderResponse)throws 
      IOException, PortletException
      {
          PortletPreferences prefs = renderRequest.getPreferences();
          String username = (String) prefs.getValue("name", "");
          String area=(String)prefs.getValue("area", "testimonial");
          String email=(String)prefs.getValue("email", "");
          String subject=(String)prefs.getValue("subject", "");
          String company=(String)prefs.getValue("company", "");
          String designation=(String)prefs.getValue("designation", "");
  
      if (username.equalsIgnoreCase ("")) 
      {
          username = "";
      }
          renderRequest.setAttribute("userName", username);
          renderRequest.setAttribute("area",area);
          renderRequest.setAttribute("email",email);
          renderRequest.setAttribute("subject",subject);
          renderRequest.setAttribute("designation",designation);
          renderRequest.setAttribute("company",company);
  
          include(viewJSP, renderRequest, renderResponse);
      }
  
      public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
              throws IOException, PortletException 
      {
          String addName = actionRequest.getParameter("addName");
  
          if (addName != null)
          {
              PortletPreferences prefs = actionRequest.getPreferences();
              prefs.setValue("name", actionRequest.getParameter("username"));
              prefs.setValue("area",actionRequest.getParameter("area"));
              prefs.setValue("email",actionRequest.getParameter("email"));
              prefs.setValue("subject",actionRequest.getParameter("subject"));
              prefs.setValue("designation",actionRequest.getParameter("designation"));
              prefs.setValue("company",actionRequest.getParameter("company"));
  
              prefs.store();
  
              testimonial testimonial = null;
  
              try {
                  testimonialLocalServiceUtil.createtestimonial(CounterLocalServiceUtil.increment());
                  testimonial.setSubject(actionRequest.getParameter("subject"));
                  testimonial.setArea(actionRequest.getParameter("area"));
                  testimonial.setUsername(actionRequest.getParameter("username"));
                  testimonial.setEmail(actionRequest.getParameter("email"));
                  testimonial.setCompany(actionRequest.getParameter("company"));
                  testimonial.setDesignation(actionRequest.getParameter("designation"));
                  testimonialLocalServiceUtil.addtestimonial(testimonial);
              } catch (SystemException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              actionResponse.setPortletMode(PortletMode.VIEW);    
          }
      }
  
      protected void include(String path, RenderRequest renderRequest, RenderResponse renderResponse)
              throws IOException, PortletException 
      {
          PortletRequestDispatcher portletRequestDispatcher = getPortletContext().getRequestDispatcher(path);
  
          if (portletRequestDispatcher == null) 
          {
              _log.error(path + " is not a valid include");
          }
          else
          {
              portletRequestDispatcher.include(renderRequest, renderResponse);
          }
      }
      protected String editJSP;
      protected String viewJSP;
      private static Log _log = LogFactory.getLog(Testimonial1.class);
  }
  </code></pre></li>
  <li><p>I have written my view logic in following file - <code>view.jsp</code> and I want to retrive data from database in following file:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %&gt;
  
  &lt;jsp:useBean id="subject" class="java.lang.String" scope="request"/&gt;
  &lt;jsp:useBean id="area" class="java.lang.String" scope="request"/&gt;
  &lt;jsp:useBean id="userName" class="java.lang.String" scope="request" /&gt;
  &lt;jsp:useBean id="email" class="java.lang.String" scope="request"/&gt;
  &lt;jsp:useBean id="company" class="java.lang.String" scope="request"/&gt;
  &lt;jsp:useBean id="designation" class="java.lang.String" scope="request"/&gt;
  &lt;portlet:defineObjects /&gt;
  
  &lt;p&gt;This is the Testimonial portlet......... how are u all ..........&lt;/p&gt;
  
  &lt;p&gt;Subject is ....&lt;%=subject %&gt;&lt;/p&gt;
  &lt;p&gt;Testimonial is .....&lt;%=area %&gt;&lt;/p&gt;
  &lt;p&gt;Hello &lt;%= userName %&gt;!&lt;/p&gt;
  &lt;p&gt;your Email ......&lt;%=email %&gt;&lt;/p&gt;
  &lt;p&gt;your company .....&lt;%=company %&gt;&lt;/p&gt;
  &lt;p&gt;You are .......&lt;%=designation %&gt;&lt;/p&gt;
  </code></pre></li>
  <li><p>My <code>service.xml</code> file</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN"  "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd"&gt;
  
  &lt;service-builder package-path="com.liferay.portlet"&gt;
      &lt;author&gt;ubuntu&lt;/author&gt;
      &lt;namespace&gt;perception&lt;/namespace&gt;
  
      &lt;entity name="testimonial" local-service="true" remote-service="true"&gt;
          &lt;column name="subject" type="String"&gt;&lt;/column&gt;
          &lt;column name="area" type="String"&gt;&lt;/column&gt;
          &lt;column name="username" type="String"&gt;&lt;/column&gt;
          &lt;column name="email" type="String"&gt;&lt;/column&gt;
          &lt;column name="company" type="String"&gt;&lt;/column&gt;
          &lt;column name="designation" type="String"&gt;&lt;/column&gt;
      &lt;/entity&gt;
  &lt;/service-builder&gt;
  </code></pre></li>
  <li><p>My <code>portal-ext.properties</code> file:</p>
  
  <pre><code>#
  # MySQL 
  #
  
  jdbc.default.driverClassName=com.mysql.jdbc.Driver 
  jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEn
  coding=UTF-8&amp;useFastDateParsing=false
  jdbc.default.username=root
  jdbc.default.password=ubuntu123
  
  schema.run.enabled=true
  schema.run.minimal=true
  </code></pre></li>
  </ol>
  
  <p>I have put all my files, now please tell me what I have to do for data insertion and retrieval.</p>
  
  <p>Pls tell am I right in insertion code? and how to retrive data from database?</p>