Friday, September 27, 2013

Installing BIRT in STS



1) Install STS 

2) Click on help -
Install New Software --> Click on Add
-> give the URL (http://download.eclipse.org/birt/update-site/4.2/)

3) Select the BIRT components you want to install--> click Next and follow the instructions such as accept terms and conditions.

4) Click on Finish, it will start installing the BIRT components.

5) It is getting installed successfully and we can see the version details on the following path: Help-
About STS
-> click on Eclipse BIRT Project

Thursday, September 26, 2013

Cookies using JSP / Servlet

Login.jsp

<form action="rem" method="POST">
Enter Value: <input type="text" name="val" value=""/>
<input type="submit" value="Submit" />
</form>

----------------------------------------------------------------------------------
RemController.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String myValue = request.getParameter("val");


    Cookie userCookie = new Cookie("u", myValue);
        userCookie.setMaxAge(60*60*24);
        response.addCookie(userCookie);


    request.getRequestDispatcher("Remember.jsp").forward(request, response);
    }
----------------------------------------------------------------------------------
Remember.jsp

<html>
 <%
        Cookie[] cookies=request.getCookies();
        Cookie cookie=null;
        if(cookies != null){
            for(int i=0; i<cookies.length; i++){
                cookie = cookies[i];
                System.out.print(cookie.getName()+": ");
                System.out.println(cookie.getValue());
            }
        }
        %>
</html>
----------------------------------------------------------------------------------

Wednesday, September 25, 2013

Login Page using Servlet / JSP

1. Servlet Mapping in web.xml

Transfering control from JSP (Login.jsp) file to a servlet (RemController.java) file.
 ----------------------------------------------------------------------------------------------------------------------------
Login.jsp

<form action="rem" method="POST">
Username: <input type="text" id="username" name="username" value=""/><br/>
Password: <input type="password" id="password" name="password" value=""/><br/>
<input type="submit" id="submit" value="Submit" /><br/>

</form>
----------------------------------------------------------------------------------------------------------------------------
web.xml

 <servlet>
    <servlet-name>RemController</servlet-name>
    <servlet-class>myPkg.RemController</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>RemController</servlet-name>
    <url-pattern>/rem</url-pattern>
  </servlet-mapping>
----------------------------------------------------------------------------------------------------------------------------
RemController.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("result", "hello!");
      
        String name = request.getParameter("username");
        String password = request.getParameter("password");
      
        System.out.println(name+" "+password);
      
    //    response.sendRedirect("Remember.jsp");
        request.getRequestDispatcher("Remember.jsp").forward(request, response);
        }
----------------------------------------------------------------------------------------------------------------------------
Remember.jsp

<html>
<body>
        <h1>Remember.jsp</h1>
        <p>The result is ${result}</p>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------

Wednesday, September 4, 2013

Database FAQ's

Finding Non-unique rows.

SELECT LIC_NO, count(LIC_NO) AS cnt FROM LM_LICENSE GROUP BY LIC_NO HAVING cnt>1;

Wednesday, August 14, 2013

JAVA FAQ's

1. Rounding of a double value to 2 digits.

-- Double TempTentSec = 0.0;
    TempTentSec = 111.0;
    TempTentSec = Math.round(TempTentSec * 100.0) / 100.0;

(Similarly to round of at 0 places:- Multiply & divide by 1.0)

2. Removing decimals without rounding off the double value.

-- TempTentSec = (double)Math.floor(TempTentSec);

Thursday, July 18, 2013

Oracle Synonym


Following query is to automatically update table data in one database based on changes in another database.

sql>create public synonym AMM_PRODUCTS_PHARMA for ALAB.AMM_PRODUCTS_PHARMA;

sql>create or replace
TRIGGER AMM_PRODUCTS_TRIGGER
after insert on APHARMA.AMM_PRODUCTS for each row
begin
insert into AMM_PRODUCTS_PHARMA
(PRD_ID,
PRD_GENERIC_NAME,
PRD_SHORT_DESC,
PRD_DESC
) values
(:new.PRD_ID,
:new.PRD_GENERIC_NAME,
:new.PRD_SHORT_DESC,
:new.PRD_DESC
);
end;

sql>create public synonym AMT_PROD_STOCK_DETAILS_PHARMA for ALAB.AMT_PROD_STOCK_DETAILS_PHARMA;

sql>create or replace trigger amm_prod_stock_details_trigger
after insert  on APHARMA.AMT_PROD_STOCK_DETAILS for each row
begin
 insert into AMT_PROD_STOCK_DETAILS_PHARMA
 (PRS_SEQ_NO,
PRS_DOC_DATE,
PRS_PER_ID,
PRS_CPY_ID
) values
(:new.PRS_SEQ_NO,
:new.PRS_DOC_DATE,
:new.PRS_PER_ID,
:new.PRS_CPY_ID
);
end;

-- By Mr. Nitesh Ghosalkar

Thursday, July 11, 2013

Entering sequence no in column of table already having data in SQL


  alter table AMM_PROD_DRUG_LICENCE add pdl_seq_no NUMBER(19,0);

update AMM_PROD_DRUG_LICENCE set pdl_Seq_no=1;

CREATE SEQUENCE pdl_sequence_no_seq
  START WITH 1
  INCREMENT BY 1
  CACHE 50;

UPDATE AMM_PROD_DRUG_LICENCE
   SET pdl_seq_no = pdl_sequence_no_seq.nextval;