Skip to main content

Decode of the image file from hibernate and struts

Create a java file for the decoding the image

Image.java

package com.img.action;

import java.awt.image.BufferedImage;

import java.io.ByteArrayOutputStream;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.LinkedHashMap;

import java.util.List;

import java.util.Map;


import javax.imageio.ImageIO;

import javax.servlet.ServletRequest;

import javax.servlet.http.HttpServletRequest;


import org.apache.struts2.ServletActionContext;


import com.img.dao.ConnectionDAO;

import com.img.pojo.Film_TablePojo;

import com.img.pojo.imagePojo;

import com.opensymphony.xwork2.ActionSupport;


public class Show extends ActionSupport {


List<Object> values = new ArrayList<Object>();

 public List<Object> getValues() {

return values;

}


public void setValues(List<Object> values) {

this.values = values;

}


/*HttpServletRequest request;

    public void setServletRequest(HttpServletRequest request) {

        this.request = request;

    }

    public HttpServletRequest getServletRequest() {

        return request;

    }    */


@Override

public String execute() throws Exception {


ConnectionDAO con = new ConnectionDAO();

values=con.nowshowing();

System.out.println(values);

return "success";

}

}


2)ConnectionDao.java


package com.img.dao;

import java.util.ArrayList;

import java.util.List;



import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.img.pojo.Film_TablePojo;
import com.img.pojo.imagePojo;
public class ConnectionDAO {

Configuration con = new Configuration().configure("hibernate.cfg.xml");
SessionFactory sf = con.buildSessionFactory();
Session session;
@SuppressWarnings("unchecked")

public List<Object> nowshowing() {
List<Object> lista1 = new ArrayList<Object>();
Session session = sf.openSession();

try {
Query qry = session.createQuery("FROM Film_TablePojo f");
lista1 = qry.list();

} catch (Exception e) {
e.printStackTrace();
}
return lista1;

}
}

3)Image Pojo table.
  
film_tablepojo.java



package com.img.pojo;



import java.util.Set;



public class Film_TablePojo {
imagePojo p;
public imagePojo getP() {
return p;
}

public void setP(imagePojo p) {
this.p = p;
}
private int flim_id;
private int cinema_id;
private String title;
private String description;
private String running_time;
private String director;
private String musicdirector;
private String artist;
private int image_id;
private int rating;
private byte[] image;
private String release_date;
public String getRelease_date() {
return release_date;
}

public void setRelease_date(String release_date) {
this.release_date = release_date;
}

public byte[] getImage() {
return image;
}

public void setImage(byte[] image) {
this.image = image;
}

public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public int getFlim_id() {
return flim_id;
}
public void setFlim_id(int flim_id) {
this.flim_id = flim_id;
}
public int getCinema_id() {
return cinema_id;
}
public void setCinema_id(int cinema_id) {
this.cinema_id = cinema_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getRunning_time() {
return running_time;
}
public void setRunning_time(String running_time) {
this.running_time = running_time;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getMusicdirector() {
return musicdirector;
}
public void setMusicdirector(String musicdirector) {
this.musicdirector = musicdirector;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public int getImage_id() {
return image_id;
}
public void setImage_id(int image_id) {
this.image_id = image_id;
}
}

(**)Create for this hbm file


(**)cretate a image file for pojo class

imagepojo.java:



package com.img.pojo;



import java.util.Date;

import java.util.Set;


import com.mysql.jdbc.Blob;
import com.sun.mail.iap.ByteArray;




public class imagePojo {

private int image_id;

private String imgName;
private String picImage;
public int getImage_id() {
return image_id;
}

public void setImage_id(int image_id) {
this.image_id = image_id;
}

public String getImgName() {
return imgName;
}

public void setImgName(String imgName) {
this.imgName = imgName;
}

public String getPicImage() {
return picImage;
}

public void setPicImage(String picImage) {
this.picImage = picImage;
}

}

(11)Create a hbm file for the image pojo class


(11)Hibernate cfg.xml:




<?xml version="1.0" encoding="UTF-8"?>



<!-- <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">


<hibernate-configuration> -->
 <!DOCTYPE hibernate-configuration SYSTEM 
    "classpath://org/hibernate/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/ticketbooking</property>

<property name="hibernate.connection.username">root</property>

<property name="connection.password">root</property>

<property name="connection.pool_size">1</property>

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="show_sql">true</property>

<property name="hbm2ddl.auto">update</property>


<mapping resource="com/img/pojo/imagePojo.hbm.xml" />
<mapping resource="com/img/pojo/Film_TablePojo.hbm.xml" />
<!-- <mapping class="com.kclink.krp.pojo.imagePojo"/> -->
  
      
</session-factory>



</hibernate-configuration>



II)struts.xml:




<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"

    "/WEB-INF/dtds/struts-2.1.dtd">

<struts>
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/> 
<package name="default" extends="struts-default">
<action name="get" class="com.img.action.Show" method="execute">  
     <result name="success">index.jsp</result>  
</action>
</package>
</struts>  





II)web.xml






<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns="http://java.sun.com/xml/ns/javaee" 

    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>image</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>NewFile.jsp</welcome-file>
    </welcome-file-list>
</web-app>







    


Comments

Popular posts from this blog

Commonly asked Top 26 Java Interview Questions

1.what is a transient variable? A transient variable is a variable that may not be serialized. If you don't want to serialize any objects then we have to use Transient Keyword. 2. Why do threads block on I/O? Threads block on i/o (that enters the waiting state) so that other threads may execute while the i/o Operation is performed. So your blocked thread of execution blocks only that: the thread of execution. 3. How are Observer and Observable used? Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects(refer 1.4). 4. What is synchronization and why is it important?                      With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Withou

All difference Question in java(common difference) (Collections)

1)Difference Between Interfaces And Abstract class? All the methods declared in the Interface are Abstract,where as abstract class must have atleast one abstract method and others may be concrete. In abstract class keyword abstract must be used for method, where as in Interface we need not use the keyword for methods. Abstract class must have Sub class, where as Interface can’t have sub classes.  An abstract class can extend only one class, where as an Interface can extend more than one. 2)Difference between Arrays and Vectors?             Because Vectors are dynamically-allocated, they offer a relatively memory-efficient way of handling lists whose size could change drastically. Arrays are fixed in size and it's wastage of memory problem. A Vector might be a good choice for such an arrangement. Moreover, Vectors have some useful member functions that make coding simpler. While in array is the bad choice of the arrangement and the code become more complex. Vecto

MYSQL Interview question..

MySQL is an open source relational database management system RDBMS based on Structured Query Language SQL MySQL runs on virtually all platforms, including Linux, Unix, Windows. Although it can be used in a wide range of applications, MySQL is most often associated with web-based applications and online publishing and is an important component of an open source enterprise. 1) What is SQL? SQL stands for Structured Query Language. SQL was initially developed at IBM in 1970s. SQL is the standard language to communicate with relational database management systems like Oracle, MS Access, MS SQL Server, MySQL, DB2 etc. It is used to connect the objects with the database . 2)what is the Purpose of SQL? • SQL is used to Create New Databases. • SQL is used to Create New Tables in a Database. • SQL is used to Insert, update, Delete records in a Database. • SQL is used to Retrieve data from a Database. • SQL is used to execute queries against a Database. • SQL can set permis