how to store and then immediately retrieve when store the image into database?

Ads
 

how to store and then immediately retrieve when store the image into database?

how to store and then immediately retrieve when store the image into database?

View Answers

September 3, 2012 at 5:58 PM

Here is a jsp code that insert and retrieve image from MYSQL database.

<%@page import="java.sql.*,java.io.*"%>
<%
try{
    InputStream sImage;
Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
File imgfile = new File("C:/flower3.jpg");
      FileInputStream fin = new FileInputStream(imgfile);
      PreparedStatement pre = con.prepareStatement("insert into image(images) values(?)");
      pre.setBinaryStream(1,fin,(int)imgfile.length());
      pre.executeUpdate();
      System.out.println("Inserting Successfully!");
      pre.close();
      Statement st=con.createStatement();
      ResultSet rs=st.executeQuery("select images from image");
if(rs.last()){
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
}
rs.close();
st.close();
con.close();
}
catch(Exception ex){
out.println("error :"+ex);
}
%>

January 9, 2013 at 11:09 AM

Inserting is done. But its not showing the image.

Ads









Related Tutorials/Questions & Answers:
how to store and then immediately retrieve when store the image into database?
How to store and retrieve image from database in JSP?
Advertisements
how to store and retrieve image from database
how to store and retrieve image using struts2 and hibernate integration
how to store,retrieve,modify the data
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
How can store image in server folder when deployed with a .war file?
How to store an image in database
How to store image into database
How to Store Image using JSF
store and retrieve data
how to store and retrieve images int and from the database using php
how to store image upload path to mssql database
how to store image upload path to mssql database
how to store image upload path to mssql database
how to store image upload path to mssql database
How to store two integer value in a separate file and retrieve those values
image store and get it back
How To Store Image Into MySQL Using Java
how to store image in oracle express edition using servlet
Unable to store the image into database
how to store image in folder and stored image path in mysql database using JSP
How to store user name,city,state,image path into database and image into folder using jsp
store and retrive image from the database
image store in oracle using jswing
store
How to store url path?
JSP and XML .data store nd retrieve
store
store & retrive the image from oracle database
retrieve data from mysql database and store it in a variable ?

Ads