Wednesday, September 3, 2014

SQL java class file using to get time



package com.allClass.SQL;

import com.allClass.Database.DatabaseConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PersonalInfo {
    private Connection con = null;
    private Statement st = null;
    private ResultSet rs = null;
    private DatabaseConnection dbc = new DatabaseConnection();


    public String getCurrentLoginInfo() {
        boolean flag = true;
        String loginInfoString = "";
        String query = "";

        this.con = this.dbc.connectDB();

        if (this.con == null) {
            flag = false;
            loginInfoString = null;
        }

        if (flag) {
            try {
                this.st = this.con.createStatement();

                query = "SELECT PKG_DRPATCAREQUERY.FNC_TODATE(SYSDATE) logInDateTime FROM DUAL";

                this.rs = this.st.executeQuery(query);

                while (this.rs.next()) {
                    loginInfoString = this.rs.getString("logInDateTime").trim();
                }
            } catch (SQLException sq) {
                loginInfoString = null;
                sq.printStackTrace();
                try {
                    this.rs.close();
                    this.st.close();
                    this.con.close();
                } catch (SQLException ex) {
                    loginInfoString = null;
                    ex.printStackTrace();
                }
            } finally {
                try {
                    this.rs.close();
                    this.st.close();
                    this.con.close();
                } catch (SQLException ex) {
                    loginInfoString = null;
                    ex.printStackTrace();
                }
            }
        }

        return loginInfoString;
    }
}


Tuesday, September 2, 2014

SYS(DATE) using DB



SELECT FNC_TODATE(SYSDATE) logInDateTime FROM DUAL

SELECT FNC_TODATE(SYSDATE) FROM DUAL


logInDateTime is alias name.

DateFormating dot java :show in java class sile

package util;

import java.util.Calendar;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class DateFormating {
   
    public Date getDate(String dateFormate, String dateString) {
        //03/06/2012
        DateFormat formater = new SimpleDateFormat(dateFormate);
       
        try {
               Date datevalue= formater.parse(dateString);
               return  datevalue;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
   
   
    public String getDateTime(Date dateString) {
        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
        String date = format.format(dateString);
        return date;
    }
   
    public String getDate(String dateString) {
        try {
            if(!dateString.isEmpty()){
                String oldDateFormat="yyyy-MM-dd";
                String newDateFormat="MM/dd/yyyy";
                SimpleDateFormat formater = new SimpleDateFormat(oldDateFormat);
                Date datevalue= formater.parse(dateString);
                formater.applyPattern(newDateFormat);
                return  formater.format(datevalue);
            }else{
                return "";
            }
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
   
    //format a date for database
    //@ getDate     this will take date from Date instance
    public Date dateFormatDB(String getDate) {
        DateFormat formater = new SimpleDateFormat("MM/dd/yyyy");
        Date datevalue;
        try {
            datevalue = formater.parse(getDate);
            return datevalue;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
   
  //format a date for the user
    //@ getDate     this will take date from Date instance
    public String dateFormatUser(Date getDate) {
        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
        String date = format.format(getDate);
        return date;
    }
   
    //format a date for the user
    //@ getDate     this will take date from Date instance
    public String dateFormatUser1(Date getDate) {
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        String date = format.format(getDate);
        return date;
    }
  //format a date for the user
    //@ getDate     this will take date from Date instance
    public String dateFormatDBOracle(Date getDate) {
        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        String date = format.format(getDate);
        return date;
    }
    public String dateFormatDBOracleD(Date getDate) {
        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
        String date = format.format(getDate);
        return date;
    }
   
    public int dateCount(String dateFrom,String dateTo){
        Date fromDate=dateFormatDB(dateFrom);
        Date toDate=dateFormatDB(dateTo);
        int dateFromInt=fromDate.getDate();
        int dateToInt=toDate.getDate();
        int totalDays=dateFromInt-dateToInt;
        return totalDays;
    }
   
   
    public Date getCalendarDate(String dateFormate, String dateString) {  //Only for  "dd/MM/yyyy"
       
        Calendar cal= Calendar.getInstance();
        Date date=null;
        DateFormat formater = new SimpleDateFormat(dateFormate);

              try {
                       Date dateValue= formater.parse(dateString);
                    cal.setTime(dateValue);  
                    date=  cal.getTime();                                 
              } catch (ParseException e) {
                  e.printStackTrace();
                 
              }          
         return  date;
      
    }
   
    public static void main(String[] args){
       
        DateFormating dfff= new DateFormating();
       
       
//    System.out.println(    dfff.getCalendarDate("MM/dd/yyyy hh:mm aa", "03/05/2013 03:14 PM"));
        System.out.println(    dfff.dateFormatDBOracle(new Date()));
       
       
       
    }

}

Java date call





 Java date call :


 Date date_today=new Date();
 //datVal = date_today.toString();
 //System.out.println("Show Time "+datVal);

How to work session variable

Java Action class :

package com.allClass.Action;


import com.allClass.Database.DatabaseConnection;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;// This is use for add field error



import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


import java.util.Date;// For date
import util.DateFormating;//For date




public class LogInPageAction extends ActionSupport{
   
    // use for log in username and passward kaniz
    private String userName;
    private String password;
    private String datVal;
   
    //
    private Connection con = null;
    private Statement st = null;
    private CallableStatement cs = null;
    private ResultSet rs = null;
    private DatabaseConnection dbc = new DatabaseConnection();
    String query = "";   

    //START Login code **************
    public String userSignIns(){
           
         int usrname = 0;
        //String usrname = "";
        System.out.println("hhhh");
            boolean fg = true;
            con = dbc.connectDB();

            if (con == null) {
                fg = false;
            }
           
           
           
            if (fg) {
                try {

                    st = con.createStatement();

                  
                   
      //rs.getString for:// query = "select USER_ID from  login_users where USER_ID='" + userName + "' and PASSWORD='" + password + "'";              
      query = "select * from  login_users where LOGIN_NAME='" + userName + "' and PASSWORD='" + password + "'";                           
                    System.out.println(query);

                    rs = st.executeQuery(query);

                    while (rs.next()) {
                        usrname = rs.getRow();
                        //usrname = rs.getString("USER_ID"); or usrname = rs.getString("LOGIN_NAME");
                       
                    }
                   
                   

                } catch (SQLException sq) {            
                    sq.printStackTrace();
                } finally {
                    try {
                        if (rs != null) {
                            rs.close();
                        }
                      
                        con.close();
                    } catch (SQLException ex) {
                        ex.printStackTrace();
                    }
                }
            }
           
           // if (!usrname.isEmpty()) {
            if (usrname>0) {
               
                //************************ Start My necessary call function ************************
               
                              // Start for date and import java dot util
                                DateFormating df=new DateFormating();
                                Date date_today=new Date();
                                 datVal=df.dateFormatDBOracle(date_today);
     ActionContext.getContext().getSession().put("logInTimekkk",datVal);
                             // End For date java dot util
               
               
                //************************ End My necessary call function ************************
               
                return "userSignIns";
            }else{
               
                addFieldError("logMsg","Your Account Is Not active!!"); //N.B: After add field error message
                return "logInFail";   
            }
           
           
            //return "enterLogInPageFail";
        }

   
   
   
   
   
   
   
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }








           
    //END Log in code ***************   
       

   

    public String getDatVal() {
        return datVal;
    }

    public void setDatVal(String datVal) {
        this.datVal = datVal;
    }
   
   
   
   
   
   
   
}





Now jsp page get session value and show this value :

   <%
 
      String loginTimeVal =(String)ActionContext.getContext().getSession().get("logInTimekkk");

%>




<tr>
  <th><span class="">Name :</span> <span><s:property value="userName"/></span>&nbsp;&nbsp;&nbsp;&nbsp;</th>
  <!-- th><span class="">Logged on at :</span> <span> <s:property value="datVal"/></span></th-->
  <th><span class="">Logged on at :</span> <span> <%=loginTimeVal %></span></th>
</tr>

Monday, September 1, 2014

scriplet tag declar in jsp page

<tr>
   <th>Name : <%=userName %></th>
   <th>Logged on at : <%=loginTime %></th>
</tr>

Sunday, August 31, 2014

Oracle Sequence create

DROP SEQUENCE RAJUK_MONEY.SEQ_BANKINFO_ID;

CREATE SEQUENCE RAJUK_MONEY.SEQ_BANKINFO_ID
  START WITH 47
  MAXVALUE 999999
  MINVALUE 1
  CYCLE
  NOCACHE
  NOORDER;




This is :


CREATE SEQUENCE SEQ_BANKINFO_ID
  START WITH 47
  MAXVALUE 999999
  MINVALUE 1
  CYCLE
  NOCACHE