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 that bytes

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









Related Tutorials/Questions & Answers:
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
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
Advertisements
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 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
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 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
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
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
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
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
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
Java file bytes
Java file bytes In this section, you will learn how to read bytes from a file...: This class obtains input bytes from a file in a file system. read()-  ... InputStream class along with the FileInputstream class to obtain the byte of data from
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 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
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 
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
ModuleNotFoundError: No module named 'bytes'
ModuleNotFoundError: No module named 'bytes'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'bytes' How to remove the ModuleNotFoundError: No module named 'bytes'
1024 bytes equals to
1024 bytes equals to  1024 bytes equals to   1024 bytes equals to 1 KB
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
How to store and retrieve image from database in JSP?
How to store and retrieve image from database in JSP?  Hi, In one of my application I have to store and then display the image in JSP. How to store and retrieve image from database in JSP? Thanks   HI, You can use
image
image   Dear every body please help me how to add and retrive image and video into oracle 11g using jsp
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
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 &
How to retrieve image from database in Servlet?
How to retrieve image from database in Servlet?  Hi, How to retrieve image from database in Servlet? Thanks   Hi, Please check the tutorial Retrieve image from database using Servlet. Thanks
How to retrieve image from mysql database in JSP?
How to retrieve image from mysql database in JSP?  Hi, I need JSP same codes for learning to get image which is stored in MySQL Database. How to retrieve image from mysql database in JSP? Thanks   Hi, You can write
How to retrieve blob image from database in JSP?
How to retrieve blob image from database in JSP?  Hello, JSP is used... the blog image from database. How to retrieve blob image from database in JSP?   Hi, Please check the tutorial Retrieve image from database using
ModuleNotFoundError: No module named 'yelp_bytes'
'yelp_bytes' How to remove the ModuleNotFoundError: No module named 'yelp_bytes' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'yelp_bytes'  Hi, My Python
ModuleNotFoundError: No module named 'bytes-string'
'bytes-string' How to remove the ModuleNotFoundError: No module named 'bytes-string' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'bytes-string'  Hi, My Python
ModuleNotFoundError: No module named 'protobuf-bytes'
named 'protobuf-bytes' How to remove the ModuleNotFoundError: No module named 'protobuf-bytes' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'protobuf-bytes'  Hi, My
ModuleNotFoundError: No module named 'bytes-warning'
'bytes-warning' How to remove the ModuleNotFoundError: No module named 'bytes-warning' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'bytes-warning'  Hi, My
How to retrieve and display image from database in Java?
How to retrieve and display image from database in Java?  Hi, I am.... Please check the it at How to store and retrieve image from database in JSP... on the web page. My application is in Java/JSP. How to retrieve and display image
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
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
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
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
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
how we retrieve image from database
how we retrieve image from database  my code is:- $search=$_POST["search"]; $sql="SELECT * FROM search WHERE productname ='$search...;lt;/table>"; mysql_close($con);   PHP retrieve image
how to upload image from jsp to mssql
how to upload image from jsp to mssql  hi there!!, i'm using jsp... database. hope u can help in my database: i have imagetbl that contain image column(to store the image) as varbinary and fileimage(to store the directory
how to upload image from jsp to mssql
how to upload image from jsp to mssql  hi there!!, i'm using jsp... database. hope u can help in my database: i have imagetbl that contain image column(to store the image) as varbinary and fileimage(to store the directory
image
image  how to add the image in servlet code
Version of com.tmiyapub>bytes-regex dependency
List of Version of com.tmiyapub>bytes-regex dependency
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
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
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

Ads