Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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



Advertisement
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
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
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
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 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 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
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
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
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
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
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
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 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
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 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
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
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 &
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
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
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
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
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
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
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
How can I Convert my Image Files to Text Files? - IDE Questions
How can I Convert my Image Files to Text Files?  How can I Convert my Image Files to Text Files
getting coords from an image.
getting coords from an image.  how to get coordinates dynamically(in run time) from an image?? pls help me
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
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
Advertisements
 

 

 

DMCA.com