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?

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.









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 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,retrieve,modify the data
How to store an image in database
How to store image into database
How to Store Image using JSF
how to store/retrieve doc file - Java Beginners
store and retrieve data
image store and get it back
how to store and retrieve images int and from the database using php
Unable to store the image into database
image store in database - JDBC
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 Image Into MySQL Using Java
How to store two integer value in a separate file and retrieve those values
how to store image in oracle express edition using servlet
store and retrive image from the 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
image store in oracle using jswing
store & retrive the image from oracle database
store
JSP and XML .data store nd retrieve
store
retrieve data from mysql database and store it in a variable ?
how to store image file and videofile in ms access database using java? - JDBC
store and retrive image from database - JDBC
Image retrieve
How to retrieve image from database
How to store url path?
How to retrieve and display image from database in Java?
Store image from html img tag into mysql db using java
How to store url path in file ?
access image from ajax store in mysql using jsp
how to write store procedure in sql
how can we store the encrypted passwaord in swings?
How to retrieve image from database in Servlet?
how to store jtable value in multidimensional array?
how to store jtable value in multidimensional array?
How to retrieve blob image from database in JSP?
How to retrieve image from mysql database in JSP?
How to Store Date - Java Beginners
how to store dynamic array in hidden field in javascript?

Ads