Monday, November 26, 2012

Run GlassFish as a Service in Windows

https://blogs.oracle.com/foo/entry/automatic_starting_of_servers_in

asadmin create-service

Friday, October 12, 2012

Simple Log System For Java Application


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fileapp;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.XMLFormatter;

/**
 *
 * @author sajjad
 */
public class MyLog {

    /**
     * @param args the command line arguments
     */
    private final static Logger LOGGER = Logger.getLogger(FileApp.class.getName());
    public static void main(String[] args) throws IOException {
// LOGGER.setLevel(Level.INFO);

 Calendar now = GregorianCalendar.getInstance();
     DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String file=dateFormat.format(date)+".log";
      file="c:/data_log/"+file;
 Handler handler;
        handler =  new FileHandler(file,true);
  handler.setFormatter(new SimpleFormatter() );
 
  LOGGER.addHandler(handler);
  LOGGER.addHandler(new ConsoleHandler());
  LOGGER.info("Our first logging message");
   LOGGER.severe("Something terrible happened");
   }
}


Saturday, September 29, 2012

redirect a page according to view parameter

in jsf page




  <f:metadata>
            
            <f:viewParam name="id" value="#{testBean.val}" />
        </f:metadata>




in managed bean

  public void setVal(String val) throws IOException {
        System.out.println("Value Set"+ new Date());
        if(val.startsWith("1"))
             FacesContext.getCurrentInstance().getExternalContext().dispatch("/foo.xhtml");
        else
            FacesContext.getCurrentInstance().getExternalContext().dispatch("/bar.xhtml");
           
        this.val = val;
    }

Wednesday, September 26, 2012

Checking NULL in PL/SQL


CREATE OR REPLACE FUNCTION date_null(
    iv_number IN DATE,dt IN DATE)
  RETURN integer
  IS
  d integer;
BEGIN

  IF iv_number is NULL THEN  d :=1;
  ELSE
    d :=2;
    
  END IF ;
   RETURN d;
   
END;


Tuesday, September 25, 2012

Functions in PL/SQL

 function definition



CREATE OR REPLACE FUNCTION larger_date(
    iv_number IN DATE,dt IN DATE)
  RETURN DATE IS
  d date;
BEGIN

  IF iv_number > dt THEN  d :=iv_number -7;
  ELSE
    d :=dt;
    
  END IF ;
   RETURN d;
   
END;


How to call in SQL

SELECT  larger_date

(sysdate-1,sysdate+1)

FROM DUAL;

Sunday, September 09, 2012

create database link with out editing tnsnames.ora



create database link a_dblink
  connect to system identified by password
 using
 '(DESCRIPTION=
   (ADDRESS=
     (PROTOCOL=TCP)
    (HOST=192.168.12.152)
    (PORT=1521))
   (CONNECT_DATA=
    (SID=my_sid)))';

Tuesday, July 17, 2012

Tuesday, April 03, 2012

XMLGregorianCalendar


XMLGregorianCalendar xgc=DatatypeFactory.newInstance().newXMLGregorianCalendarDate(year, month, day, timezone);


Monday, February 06, 2012

JPA


Query q=em.createQuery("select sum(o.montant) from Operation o join
o.codTransac t join o.codCaisse c where (t.sens='D')and
(c.dateCaisse=o.dateOp)");





Query q = em.createQuery("DELETE FROM Subscription s WHERE s.subscriptionDate < :today");
q.setParameter("today", new Date());
int deleted = q.executeUpdate();



Date now = new Date();
Date thirtyDaysAgo = new Date(now.getTime() - (30 * MS_IN_DAY));

Query q = em.createQuery("Select m from Message m "
    + "where m.targetTime < :now and m.targetTime > :thirtyDays");
q.setParameter("now", now);
q.setParameter("thirtyDays", thirtyDaysAgo);

List<Message> results = (List<Message>) q.getResultList();

Saturday, January 21, 2012

Handling ViewExpiredException


  1.  <error-page>
  2.         <exception-type>javax.faces.application.ViewExpiredException</exception-type>
  3.         <location>/faces/viewExpired.xhtml</location>
  4.     </error-page>

Sunday, January 08, 2012

Accessing another managed beans property


FacesContext facesContext = FacesContext.getCurrentInstance();
NeededBean neededBean
    = (NeededBean)facesContext.getApplication()
      .createValueBinding("#{neededBean}").getValue(facesContext);