how to convert image into bytes and also retrive the image from that bytes

Ads
 

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

Ads









Related Tutorials/Questions & Answers:
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
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
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
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 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
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
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
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
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 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
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
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 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
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'
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
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
1024 bytes equals to
1024 bytes equals to  1024 bytes equals to   1024 bytes equals to 1 KB
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 &
image
image   Dear every body please help me how to add and retrive image and video into oracle 11g using jsp
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
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
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 '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
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 '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
getting coords from an image.
getting coords from an image.  how to get coordinates dynamically(in run time) from an image?? pls help me

Ads