Friday, January 31, 2014

Image Upload Code From Local pc

Jsp page
<s:form action="userImage" method="post" enctype="multipart/form-data">
<div id="Row_9_B" style="float:left;width:527px;height:auto;margin-bottom:2px;display:none;">
              <div id="" style="float:left;width:150px;height:auto;text-align:right; " class="fontSize1">Please specify a file:</div>
              <div id="" style="float:left;width:325px;height:auto;text-align:left;" class="fontSize1">
<!--input type="file" name="datafile" size="25"-->
<div style="float:left; width:250px; text-align:right;">
<s:file  id="userImage" name="userImage" label="Patient Image" />
</div>
<div style="float:left; width:75px;" >
<!--input  id="take" name="" value="Submit" type="button" onclick="takeLoadImage('userImage')"/  USE FOR SCRIPT -->

</div>
</div>
</div>       
     
     
     
      <div id="Row_PriorApp" style="float:left;width:527px;height:auto;margin-bottom:2px;">
              <div id="" style="float:left;width:480px;height:auto;text-align:right;" class="fontSize1"><s:actionerror /></div>
              <div id="hereImageSet_div" style="float:left;width:480px;height:auto;text-align:left; text-align:center;" class="fontSize1">
              </div>
      </div>
</s:form>
Info: struts default method is execute
struts file
 <!--  My Change -->
        <action name="userImage" class="com.allClass.Action.ImageLoadAction">
            <interceptor-ref name="fileUpload">
                <param name="maximumSize">2097152</param>
                <param name="allowedTypes">image/png,image/gif,image/jpeg,image/pjpeg
                </param>
            </interceptor-ref>
            <interceptor-ref name="defaultStack"></interceptor-ref>
            <result name="success">/Patient/registration.jsp</result>
            <result name="input">/Patient/registration.jsp</result>
        </action>


ImageLoadAction.java
package com.allClass.Action;

import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.allClass.Model.ReasonAppPatientInfo;
import com.opensymphony.xwork2.ActionSupport;

import Database.DatabaseConnection;
import SQLQuery.Patient.ReasonAppointmentSql;

// extends ActionSupport (This part use fot addActionError also use tag in jsp page N.B:<s:actionerror />)

public class ImageLoadAction extends ActionSupport implements ServletRequestAware {
   
    private File userImage;
    private String userImageContentType;
    private String userImageFileName;
    //private String userImageFileName;

    private HttpServletRequest servletRequest;
    private Connection con = null;
    private DatabaseConnection dbc = new DatabaseConnection();
   

   
    public String execute() {
        System.out.println("Name");
    try {

        String filePath = servletRequest.getRealPath("/");
        //String filePath = "c:/Rokon";
       
        System.out.println("Server path:" + filePath);
        File fileToCreate = new File(filePath, this.userImageFileName);

        if(userImage !=null){      // No need this line first time condition base
            FileUtils.copyFile(this.userImage, fileToCreate);
           
                 //insert image into database
           
                //String filePath = servletRequest.getRealPath("/");
                filePath += userImageFileName;           
                File image = new File(filePath);
                System.out.println(image);
                FileInputStream   fis = new FileInputStream(image);
               
                //insert image into database
                //======================
                con = dbc.connectDB();
                String sql = "insert into mypictures (photo) values (?)";
                PreparedStatement stmt = con.prepareStatement(sql);
                stmt.setBinaryStream(1, fis, (int) image.length());
               
                stmt.execute();

                con.commit();
                fis.close();
                con.close();
        } // No need this line first time condition base
        //String filePath1 = servletRequest.getRealPath("/");
        //String filePath1 = "c:/Rokon/";
       
    } catch (Exception e) {
        e.printStackTrace();
        addActionError(e.getMessage());
       
        appSuccessPage();
        return INPUT;
    }
    appSuccessPage();
    return SUCCESS;
}

   
    //  Not database save
    /*public String execute() {
        try {

            String filePath = servletRequest.getRealPath("/");
            //String filePath = "c:/Rokon";
           
            System.out.println("Server path:" + filePath);
            File fileToCreate = new File(filePath, this.userImageFileName);

            FileUtils.copyFile(this.userImage, fileToCreate);
            //String filePath1 = servletRequest.getRealPath("/");
            //String filePath1 = "c:/Rokon/";
             con = dbc.connectDB();
               
                String sql = "insert into MYPICTURES (photo) values (?)";
                PreparedStatement stmt = con.prepareStatement(sql);
              
                //String filePath = servletRequest.getRealPath("/");
                filePath += userImageFileName;
                File image = new File(filePath);
                System.out.println(image);
                FileInputStream   fis = new FileInputStream(image);
                stmt.setBinaryStream(1, fis, (int) image.length());
                stmt.execute();

                con.commit();
                fis.close();
                con.close();
        } catch (Exception e) {
            e.printStackTrace();
            addActionError(e.getMessage());

            return INPUT;
        }
        return SUCCESS;
    }*/
   
   
   
   
   
   
   
    public File getUserImage() {
        return userImage;
    }

    public void setUserImage(File userImage) {
        this.userImage = userImage;
    }

    public String getUserImageContentType() {
        return userImageContentType;
    }

    public void setUserImageContentType(String userImageContentType) {
        this.userImageContentType = userImageContentType;
    }

    public String getUserImageFileName() {
        return userImageFileName;
    }

    public void setUserImageFileName(String userImageFileName) {
        this.userImageFileName = userImageFileName;
    }

    @Override
    public void setServletRequest(HttpServletRequest servletRequest) {
        this.servletRequest = servletRequest;

    }

    public HttpServletRequest getServletRequest() {
        return servletRequest;
    }


   
   
    // My Start **************
   
   
    public void appSuccessPage(){
        System.out.println("Appointment Success Page .. . .. ");
        ReasonAppointmentSql reasonAppointmentSql = new ReasonAppointmentSql();
        reasonAppointmentSql.addPatientA(reg_no,dob,gender,patType_id,docChember_id,sp_dr,reason_consul,ch_complain);
        //return "appSuccessPage";
       
    }
   
    private List patientSeqList = new ArrayList<ReasonAppPatientInfo>();
    public void serialMaintainPage(){
        System.out.println("Serial No Azax Page:  return List ");
        ReasonAppointmentSql reasonAppointmentSql = new ReasonAppointmentSql();
        patientSeqList=reasonAppointmentSql.serialMain(speciality_id);
        //return "serialMaintainPage";
    }
   
    private String reg_no;
    private String  dept_id;
    private String  speciality_id;
    private String  sp_dr;
    private String  superen_id;

    private String  medicalOfficer_id;
    private String  ch_complain;
    private String  reason_consul;


    private String  docChember_id;
    private String  gender;
    private String  dob;
    private String  patType_id;
   



    public Connection getCon() {
        return con;
    }

    public void setCon(Connection con) {
        this.con = con;
    }

    public DatabaseConnection getDbc() {
        return dbc;
    }

    public void setDbc(DatabaseConnection dbc) {
        this.dbc = dbc;
    }

    public String getReg_no() {
        return reg_no;
    }

    public void setReg_no(String reg_no) {
        this.reg_no = reg_no;
    }

    public String getDept_id() {
        return dept_id;
    }


    public void setDept_id(String dept_id) {
        this.dept_id = dept_id;
    }

    public String getSpeciality_id() {
        return speciality_id;
    }

    public void setSpeciality_id(String speciality_id) {
        this.speciality_id = speciality_id;
    }

    public String getSp_dr() {
        return sp_dr;
    }

    public void setSp_dr(String sp_dr) {
        this.sp_dr = sp_dr;
    }

    public String getSuperen_id() {
        return superen_id;
    }

    public void setSuperen_id(String superen_id) {
        this.superen_id = superen_id;
    }


    public String getMedicalOfficer_id() {
        return medicalOfficer_id;
    }

    public void setMedicalOfficer_id(String medicalOfficer_id) {
        this.medicalOfficer_id = medicalOfficer_id;
    }

    public String getCh_complain() {
        return ch_complain;
    }

    public void setCh_complain(String ch_complain) {
        this.ch_complain = ch_complain;
    }

    public String getReason_consul() {
        return reason_consul;
    }

    public void setReason_consul(String reason_consul) {
        this.reason_consul = reason_consul;
    }

    public String getDocChember_id() {
        return docChember_id;
    }

    public void setDocChember_id(String docChember_id) {
        this.docChember_id = docChember_id;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }


    public String getDob() {
        return dob;
    }


    public void setDob(String dob) {
        this.dob = dob;
    }


    public String getPatType_id() {
        return patType_id;
    }


    public void setPatType_id(String patType_id) {
        this.patType_id = patType_id;
    }

   
   
   
   
   

    public List getPatientSeqList() {
        return patientSeqList;
    }
    public void setPatientSeqList(List patientSeqList) {
        this.patientSeqList = patientSeqList;
    }


   
   
   
   
   
   
   
   
   
   
    //My  End **************   
   
   
}

web.xml configuration

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Struts2 Application</display-name>
    <listener>
        <listener-class>
            org.apache.struts2.tiles.StrutsTilesListener
        </listener-class>
    </listener>
    <context-param>
        <param-name>tilesDefinitions</param-name>
        <param-value>/WEB-INF/tiles.xml</param-value>
    </context-param>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
      <!--<welcome-file>UserImage.jsp</welcome-file>-->
        <welcome-file>pages/downloadPage.jsp</welcome-file>
        <!--<welcome-file>pages/Copy of downloadPage.jsp</welcome-file>-->
    </welcome-file-list>

</web-app>

If return Page is SuccessUserImage.jsp then -
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Success: Upload User Image</title>
</head>
<body>
    <%-- <h2>Struts2 File Upload Example</h2>
    User Image: <s:property value="userImage"/>
    <br/>
    Content Type: <s:property value="userImageContentType"/>
    <br/>
    File Name: <s:property value="userImageFileName"/>
    <br/> --%>
    Uploaded Image:
    <br/>
    <img src="<s:property value="userImageFileName"/>"/>

</body>
</html>
**/ Find the image in the following path server
Required :Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Project name

Hibernate Project&DB Connect with Orcl&Mysql and Covert DB 1 into another Format

Info: For eclipse tools jdk install not need but net been tools need jdk

**/ Hibernate Project ? 1. xml base and  2.annotation base

Oracle Library Need Jar : ojdbc14.jar
Mysql Library Need Jar : mysql-connector-java-5.1.12-bin.jar

WebContent/WEB-INF/classes/hibernate.cfg.xml configure 4 orcl
<hibernate-configuration >
    <session-factory>
        <property name="connection.useUnicode">true</property>
        <property name="connection.characterEncoding">UTF-8</property>

        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@192.168.0.246:1521:orcl</property>       
        <property name="connection.username">bfa</property>
        <property name="connection.password">bfa</property>
       
       
        <!-- oracle dialect -->
        <property name="dialect">org.hibernate.dialect.OracleDialect</property>
        <property name="current_session_context_class">thread</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
        <property name="show_sql">true</property>   
        <property name="hbm2ddl.auto">update</property>
    </session-factory>
</hibernate-configuration>



WebContent/WEB-INF/classes/hibernate.cfg.xml configure 4 mysql
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cid3</property>
    <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password">If its have password then write it HERE</property>
    <property name="hbm2ddl.auto">create</property>

                                                          Difference

   <property name="dialect">org.hibernate.dialect.OracleDialect</property>
   <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
   <property name="connection.url">jdbc:oracle:thin:@192.168.0.246:1521:orcl</property>
   <property name="connection.username">bfa</property>
   <property name="connection.password">bfa</property>




Learn How to open net been project and connect orcl database  
Now convert orcl database into mysql database.For this please at first mysql database create(blank database from php myadmin [wamp]) and  just connectivity change into mysql and project run then auto table create in mysql blank database

N.B (Mysql to orcl): If  I  want to do above instruction reverse situation then I have to type 1st time create then 2nd time type update , such as -
1st time : <property name="hbm2ddl.auto">create</property>
2nd time :<property name="hbm2ddl.auto">update</property> [ For  This situation above line no need ]


*/Learn How to open net been project and connect orcl database  Details

Wednesday, January 29, 2014

Access Modifier

1. Public 
2. Protected
3. Private
4. Default 


**/ Method and Variable always public  in interface

Friday, January 24, 2014

JavaPrimitiveData Type

Data Type : http://cs-fundamentals.com/java-programming/java-primitive-data-types.php 
Java's 8 type primitive data type

Data Type               Wrapper Class( It can be return )
int                              Integer
long                           Long
boolean                     Boolean
string                         String
double                       Double
float                           Float
byte                           Byte
short                          Short

**Data Type( No return that means void ) 
**Wrapper Class( It can be return )

*/ Boolean literals are only two logical values: true and false.
The true literal in Java does not equal 1, nor does the false literal equal 0. In Java, they can only be assigned to variables declared as boolean.

*/ Non primitive are object.

*/ Java exception handling is managed via five keywords: try, catch, throw, throws, and finally.

Data Type Default Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
String (or any object)   null
boolean false

Oracle ( Log in code ) query, make db & java LogIn code


SET DEFINE OFF;
Insert into LOGIN_USER
   (USR_ID, USRNAME, USRPW, USRTYPE, EMAIL,
    ACT_FG, CRE_DT, CRE_BY, UPD_DT, UPD_BY,
    USRIMG, GENDER, CONTACT_NO, EMP_ID)
 Values
   (1, 'kaniz', '`“ºŒt¨©dve;WÌ^h8Ë$    Ð', NULL, NULL,
    1, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL);
COMMIT;


USR_ID = 1
USRNAME = as wish

Coloumn USRPW  = 6093BA8C74A8A96476653B57CC5E6838CB2409D0
USRTYPE = empty
EMAIL = empty
ACT_FG = 1
CRE_DT = empty
CRE_BY = empty
UPD_DT = empty UPD_BY = empty

And others coloumn empty


Log in Code
//START Login code **************
/*public String quickRegPage(){
           
            String usrname = "";
            String usrpw = "";
            boolean fg = true;
        con = dbc.connectDB();

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

                  st = con.createStatement();

                query = "select usrname from  login_user where usrname='" + userName + "' "
                        + " and usrpw= pkg_password.encrypt_passmd5('" + password + "') "
                        + " and nvl(act_fg,'0')='1'";
                System.out.println(query);

                rs = st.executeQuery(query);

                while (rs.next()) {
                  usrname = rs.getString("usrname");
                 
                }

            } catch (SQLException sq) {            
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }
                  
                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }
       
        if (!usrname.equals("") || usrname!="" && !usrpw.equals("") || usrpw!="") {
            return "quickRegPage";
        }else{
            return "quickRegPageFail";   
        }
       
       
            //return "quickRegPageFail";
      }*/
           
//END Log in code ***************  

Make Schema(using orcl) & Login Toad & Listener Make from tns


Make New Schema then open toad and login :
Make Schema :
Start -> run-> sqlplus -> then show the black screen  then type
 sys/sys as sysdba
 create user kanizSchema  identified by  kanizSchema;
 grant dba to  kanizSchema ;


Then toad open and log in

User/schema
kanizSchema  
password
kanizSchema

Direct   ->host(192.168.0.150)->->port(1521)
Service Name:orcl




Listener Make from tns and import(download database):
Show Screen shot 
OR See it and try to understand......