Home Answers Viewqa Java-Beginners how to convert image into bytes and also retrive the image from that bytes

 
 


Senthil kumar
how to convert image into bytes and also retrive the image from that bytes
2 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners

View Answers

December 30, 2008 at 3:04 AM


Hi friend,

Code to help in solving the problem :

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DisplayImage extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
//PrintWriter pw = response.getWriter();
String connectionURL = "jdbc:mysql://192.168.10.59:3306/example";;
java.sql.Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(connectionURL,"root","root");
Statement st1=con.createStatement();
ResultSet rs1 = st1.executeQuery("select image from pictures where id='5'");
String imgLen="";
if(rs1.next()){
imgLen = rs1.getString(1);
System.out.println(imgLen.length());
}
rs1 = st1.executeQuery("select image from pictures where id='5'");
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
System.out.println("index"+index);
st1.close();
response.reset();
response.setContentType("image/jpg");
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
}
}
catch (Exception e){
e.printStackTrace();
}
}
}

Thanks


February 20, 2011 at 1:27 AM


This exemple show you how to store byte array in data base and retrive it again. with postgres or mysql using java

http://jee-best-practices.blogspot.com/2011/02/save-images-into-database.html









Related Pages:
how to convert image into bytes and also retrive the image from that bytes - Java Beginners
how to convert image into bytes and also retrive the image from that bytes  how to convert image into bytes and also retrive the image from... = st1.executeQuery("select image from pictures where id='5'"); String imgLen
How to use bytes
How to use bytes  I have saved my project and uploaded the picture...(rs.getBytes("employeephoto")); How to get the correct answer to view the picture by using bytes?   InputStream sImage; if(rs.next()){ byte[] bytearray
how to retrive other details with an image - Swing AWT
how to retrive other details with an image  hello I m trying to retrive an image as well as some other values from database.. but only image..... followingis my code..plz advice me how to get both values as well as image at a same
Counting bytes on Sockets,java tutorial,java tutorials
. To me, just knowing how many bytes were flowing past was not enough. I also... at was the number of bytes transferred over the network from... Inputstream in the IO chain. * It also dumps the bytes read into a file
image retrive into DataBase - JDBC
image retrive into DataBase  Dear Deepak Sir, How to retrive... shows you how to retrieve image from database using a servlet and then show..., Retrieving image from database is easy task. JDBC provides all the necessary API
store and retrive image from the database
store and retrive image from the database  please provide me with the code and the explanation of what each line does for the below query. -how to store and retreive images from sql database using sql commands -how to store
Java file bytes
Java file bytes In this section, you will learn how to read bytes from a file... input bytes from a file in a file system. read()-  This is the method... InputStream class along with the FileInputstream class to obtain the byte of data from
store & retrive the image from oracle database
store & retrive the image from oracle database  how can i store the image path in tha database & fetch that image from oracle database
How to retrive an inmage from database and displaying it in imgae box - Swing AWT
How to retrive an inmage from database and displaying it in imgae box ...? I want to retrive an image from database and to display it in a small imagebox... = con.createStatement(); ResultSet rs =stmt.executeQuery("select image from image where image
store and retrive image from database - JDBC
store and retrive image from database  how to store and retrive an image in database using java?  Hi friend, Code for store image...()); } } } For retrieve image from database visit to : http
How to get bytes from ByteBuffer in java.
How to get bytes from ByteBuffer in java.       ...;  In this tutorial, we will discuss how to get bytes from buffer...() method of ByteBuffer class  reads bytes of from  buffer's
retrive image from database using jsp without stream
retrive image from database using jsp without stream  How to retrive image from database using jsp without stream like (inputStream
How to read bytes from a Linked list - Java Beginners
How to read bytes from a Linked list  i have stored byte array into a linked list. How to read the bytearray dta byte after byte from a linked list.Thanking u in advance Sameer
Order bytes from most significant to least significant.
Order bytes from most significant to least significant. In this tutorial we will discuss on how to use the ByteOrder class for ordering bytes from most significant to a least significant. Code: import 
Order bytes from least significant to most significant.
Order bytes from least significant to most significant. In this tutorial we will discuss on how to use the ByteOrder class for ordering bytes from least significant to a most significant. Code: import 
jsp retrive image - JSP-Interview Questions
jsp retrive image  How to Display Images in JSP retrieved from MYSQL database? plz help me..  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/retrieve-image.shtml Thanks
Display Image on JDesktopPane
Display Image on JDesktopPane In this section, you will learn how to retrieve... in the given example, we have retrieved an image in the form of bytes and the method createImage() get these bytes and allowed the retrieved image
Place array of bytes in buffer
Place array of bytes in buffer In this tutorial you will see how to place array of bytes in buffer. The put method of CharBuffer class transfers the entire content of the given source character array into a buffer. Code
insert and retrive image from sql server database in jsp
insert and retrive image from sql server database in jsp  what is the code to insert and retrive an image from sql server database in jsp
How to retrieve image from database
How to retrieve image from database  hi........ How to retrieve image from database when it is stored. I have stored image in postgresql and want to retrieve in java form. Can u tel me hw to do? I am trying n able to do also
how to convert string to image in java
how to convert string to image in java  how to convert string to image in java? I know we need to convert image to a byte array at some point in my application but do not know how to convert a image into byte string. Please
how to display or retrive an image in jsp whose path is stored in oracle database
how to display or retrive an image in jsp whose path is stored in oracle database  how to display or retrive an image in jsp whose path is stored in oracle database and the image is stored in my pictures folder
Image Processing Java
; import com.sun.media.jai.widget.DisplayJAI; /* * Shows how to save an image...Image Processing Java  Using This Code I Compressed A JPEG Image And the Original Size of the image is 257kb and The Compressed Image Size Is 27kb
image display
for uploading image in ms access database and also seen the result of displaying image from access database but Sir I want that how I display image from database...image display  hello sir this is saurav srivastav, I am developing my
1024 bytes equals to
1024 bytes equals to  1024 bytes equals to   1024 bytes equals to 1 KB
convert tiff image to gif image - WebSevices
convert tiff image to gif image  please tell me "how to convert tiff image to gif image?" using php code for the purpose of "i want to upload and resize the tiff image?" plz inform if there any idea?   Hi I am
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
how to store and retrieve image from database
how to store and retrieve image from database  how to store and retrieve images into database(oracle) and how to retrive images from database using jsp   Here is a jsp code that insert and retrieve image from mysql
how to convert image file to text file?
how to convert image file to text file?  hi, can anybody tell how to convert image file to text file? plz help me
retriving image from database - JSP-Servlet
retriving image from database  how to retrive image from mysql database by using servlet programming  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/retreiveimage.shtml Thanks
concatenation of Two bytes in C
concatenation of Two bytes in C  Hi, I need to concatenate two bytes array in C.How to do that. bytes[0] = (n >> 24) & 0xFF; bytes[1] = (n >> 16) & 0xFF; bytes[2] = (n >> 8) & 0xFF; bytes[3] = n &
Convert Black & White Image to Color Image
Convert Black & White Image to Color Image       How to convert a black and white photograph to color? This is an easy tutorial to learn easily the methods to convert blank
image retreival
image retreival  I ve stored the path of image and audio in mysql database. how to retrive it and display... Can u pls help me out
getting coords from an image.
getting coords from an image.  how to get coordinates dynamically(in run time) from an image?? pls help me
Fetching image from database
Fetching image from database  I have uploaded image path and image name in database so, now how can i display that image using JSP or HTML page(is it possible to display using tag using concatination). image path i have stored
Image_creation
Image_creation  how to create an image from a set of pixel values stored in array - in java
How to use flickr image in Flex
How to use flickr image in Flex  Hi, I want to diaply the flickr... if you load them straight from the flickr server. I also wanted to set bitmap..., and that also requires access to the bitmapData of the loaded image. So the answer
how to insert the physical path of an image in database - JDBC
, the image column is of varchar datatype.. plz can you tell me how to insert image's path.. and also how to retrive that image path and show that picture in a small...how to insert the physical path of an image in database  hello I m
Conversion from color to Gray Image - Java Beginners
Conversion from color to Gray Image  Hi... Sakthi here.. i am new to java. and i haven't try this so far How to convert the color image...... Thanks in advance ...  Hi Friend, You can convert the color image
Image retrieve
Image retrieve  HI.. store image path/data Java Coding. ... It's supposed to take the image, store it in a directory as well as pass the image path to mysql database... Now I want to retrieve the data from directory using path
Image Album
Image Album  hi, i want to save image on server folder. and i want to save URL of this folder and name of image in database.on click of a link it retrieves the image data from server folder according to URL and File name stored
image upload
image upload  How to access image file from database using jsp?  ... rs=st.executeQuery("SELECT images FROM image WHERE id = 1"); if(rs.next...("image/jpeg"); while((size=sImage.read(bytearray))!= -1
how to display image with listview
how to display image with listview  How can i display the list view with the related images from database
Inserting Image into table
Inserting Image into table  In this section , we will insert a image into a table. For inserting image, table's field (in which image..._increment,name varchar(30), city varchar(30),image blob,PRIMARY KEY(id
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
Insert and Retrieve Image - JSP-Servlet
servlet or jsp and html form and brief explanations on how to insert and retrieve image from Microsoft sql database 2000 not Mysql please as sent to me earlier... ----------------------------------- This is Retrive image code
Data extraction from an image file.
data from the the image which also include deleted data.Can i used java to extract these data from the image file? Which are the libraries to be used...Data extraction from an image file.  I have made an image

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.