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




Have Programming Question? Ask it here!
 
 
 


Shibin Varghese
BLOB
2 Answer(s)      4 years and 11 months ago
Posted in : SQL



Advertisement
View Answers

August 28, 2009 at 1:48 PM


Hi Friend,

Try the following code:

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

public class InsertAndRetrieveImage extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
int id=5;
String connectionURL = "jdbc:mysql://localhost:3306/test";;
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(connectionURL, "root", "root");
PreparedStatement ps = con.prepareStatement("INSERT INTO image VALUES(?,?)");
File file = new File("C://node.jpg";);
FileInputStream fs = new FileInputStream(file);
ps.setInt(1,id);
ps.setBinaryStream(2,fs,fs.available());
int i = ps.executeUpdate();
ps.close();
con.close();
}
catch(Exception ex){}
Blob image = null;
Statement stmt = null;
ResultSet rs = null;
ServletOutputStream out = response.getOutputStream();
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
stmt = con.createStatement();
rs = stmt.executeQuery("select image from image where image_id = '1'");
if (rs.next()) {
image = rs.getBlob(1);
} else {
response.setContentType("text/html");
out.println("<html><head><title>Display Blob Example</title></head>");
out.println("<body><h4><font color='red'>image not found for given id</font> </h4></body></html>");
return;
}
response.setContentType("image/gif");
InputStream in = image.getBinaryStream();
int length = (int) image.length();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
while ((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length);
}
in.close();
out.flush();
} catch (Exception e) {
response.setContentType("text/html");
out.println("<html><head><title>Unable To Display image</title></head>");
out.println("<body><h4><font color='red'>Image Display Error=" + e.getMessage() + "</font></h4></body></html>");
return;
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

}

Thanks


August 28, 2009 at 1:51 PM




Related Tutorials/Questions & Answers:
get Blob
get Blob   how i can display a Blob in XHTML (i developpe with hbernate
Blob column
Blob column  Hi all... How to store an excel file in Blob column? I m using oracle 11 g database
Advertisements
Oracle BLOB
Oracle BLOB  Can anyone send me the code for inserting an image or audio into the oracle database using BLOB datatype. Plz...it's useful for my project
BLOB - SQL
as BLOB in the mysql database and retrieve the image and display it in the web...){} Blob image = null; Statement stmt = null; ResultSet rs...("Display Blob Example"); out.println("image not found for given id
Blob update in hibernate
Blob update in hibernate  Hi , I wanted to upload a blob into mysql database using hibernate. Could you please help me . Thanks in advance, Satchidanand Mohanty
Blob images - JSP-Servlet
Blob images  Hi sir how can i retrieve blob images from database using jsp from mysql  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/retrieve-image.shtml Hope that it will be helpful
MySQL BLOB
MySQL BLOB This example illustrates how to create the BLOB type field... field blob type.   Query  ..., `image` blob, PRIMARY KEY(`id`) );  
upload SQL BLOB and CLOB - JDBC
upload SQL BLOB and CLOB  Please explain upload SQL BLOB and CLOB
Blob - JSP-Servlet
Blob  Hi Friend, Thank you very much for all the answers. I need the code for reading a BLOB field(image) from the database and write the same to a file(jpg file) using JSP. Thank you in advance  Hi Friend, Use
using Blob in jdbc - JDBC
using Blob in jdbc  Hi, I got an Exception when i was trying to insert one image into oracle 10g database the exception is Exception in thread "main" java.sql.SQLException: ORA-01460: unimplemented or un reasonable
Big Blob Structure
Java Notes Big Blob Structure A common style of programming is to put all processing  in the GUI. This works Ok as long at the "model", the logic, is so small that it isn't worth putting into a separate
Get Blob
Get Blob       Blob is known as 'binary large object', is a collection of binary data... where you want to retrieve image saved as blob.    2. Create
get and display blob from mysql on jsf
get and display blob from mysql on jsf  i want to get blob from mysql, and display on jsf page. your examples with jsp. i dont find an example with jsf. plese help me about this. thanks..   Have a look at the following
Insert Mysql Blob data
Insert Mysql Blob data   In this section, we will discuss about how to insert a blob data into a database table. A Blob stores a binary large object in the database table's row. Blob object contains a logical pointer
how to retrieve blob data - JSP-Servlet
how to retrieve blob data  How to retrieve the BLOB table having single row single column in Database containing memory information using JSP as a table format?   Hi friend, I am sending you a link. I hope
pint multiple images from blob database
pint multiple images from blob database  How to display multiple images using blob from mysql database. The program code is as below: <TABLE cellpadding="15" border="1" style="background-color: #ffffcc;"> <
how to expose blob in restful web service client java
how to expose blob in restful web service client java   how to expose blob in restful webservice clientside and how to convert the blob into a file,please help me
how to expose blob in restful web service client java
how to expose blob in restful web service client java   how to expose blob in restful webservice clientside and how to convert the blob into a file,please help me
Spring 3.2 MVC insert and retrieve blob from the database
In this section, you will learn about inserting and retrieving blob from the database
Difference between Normal Insert and BLOB insert
Difference between Normal Insert and BLOB insert  I have sql database...\Pictures\Sample Pictures\Tulips.jpg', SINGLE_BLOB) AS BLOB) Here is the code... normal insert image.. I dont want to use AS BLOB in insert statement   
how to expose blob in restful web service client java rest template
how to expose blob in restful web service client java rest template  how to expose blob in restful web service client java rest template
Servlet Example To Display Mysql Blob Data
Servlet Example To Display Mysql Blob Data    ... type BLOB. The BLOB type stores/retreives large binary objects such as PDF files, video clips, JPEG/GIF pictures, and Microsoft word documents. A BLOB
store the image in the oracle using blob and get it back - JDBC
store the image in the oracle using blob and get it back  hi i am... { PreparedStatement ps = conn.prepareStatement("INSERT INTO IMAGES VALUES (?, empty_blob... by // InputStream is = rs.getBinaryStream(1); Blob blob = rs.getBlob(1
How to save excel sheet into mysql database using blob or clob
How to save excel sheet into mysql database using blob or clob  Hi All, I am new to java and i need to upload excel sheet to mysql, please suggest... know to go further, which one should i use BLOB or CLOB ? I have tried using
Servlet Example To Delete Mysql Blob Data
Servlet Example To Delete Mysql Blob Data    BLOB data in SQL is a built-in type used for storing Binary Large Object. The BLOB type stores/retreives large binary objects such as PDF files, video
Insert Blob(Image) in Mysql table using JSP
Insert Blob(Image) in Mysql table using JSP In this Section, we will insert blob data(image) in Mysql database table using JSP code. A Blob stores a binary large object in the database table's row. Blob object contains a logical
Deleting Blob Data from Database table using servlet
Deleting Blob Data from Database table using servlet In this section, we will discuss about how to insert a blob data into a database table. A Blob stores a binary large object in the database table's row. Blob object
store the image in the oracle using blob and get it back - JDBC
store the image in the oracle using blob and get it back  hi i am... { PreparedStatement ps = conn.prepareStatement("INSERT INTO IMAGES VALUES (?, empty_blob... by // InputStream is = rs.getBinaryStream(1); Blob blob = rs.getBlob(1
Display Mysql "Blob" data using servlet
will discuss about how to display a blob data stored in database table. A Blob stores a binary large object in the database table's row. Blob object contains a logical pointer which points to the Blob data, data is not directly
Display Blob(Image) from Mysql table using JSP
Display Blob(Image) from Mysql table using JSP In this section, we will display blob data(image) from Mysql database table using JSP code. A Blob stores a binary large object in the database table's row. Blob object contains
Inserting Image into table
_increment,name varchar(30), city varchar(30),image blob,PRIMARY KEY(id...;, we pass the binary file content to the BLOB column . Syntax of "
".txt" to sql with JDBC
".txt" to sql with JDBC  how to insert ".txt" into sql result[BLOB] with JDBC
Oracle - JDBC
Oracle  How to Use Blob and Clob Data types in Oracle...  Hi friend BLOB : Binary Large Object CLOB : Character Large Object Default storage each time a BLOB or CLOB exceeds 4000 bytes you could cause
problem in servlet program
problem in servlet program  Dear Sir, I have a problem to insert the Blob type data like as video file, audio file in the database using Servlet and html code
Roshni
Datatype in SQL  when we want store image which datatype is used in mysql?   You can use blob, longblob datatype to store image into mysql database. Java Store Image into MySQL
image display - JSP-Servlet
image display  how to display image that store in mysql database... column have BLOB datatype....  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/retrieve-image.shtml Thanks
3 queries on java class
3 queries on java class  Hey. I need to do 3 queries on same class ( JAVA) One is to populate the combobox, the another one to populate tje jlist and the last one to use on button to open a file from database (BLOB) Can some
downloading a file directly from mysql using java
downloading a file directly from mysql using java  Hi, I am trying to come up with a code to download a file that is on a mysql database (in form of a blob) without using url. Can anyone tell me how it can be done because I am
Resize image stored in database
Resize image stored in database  hi, Can any one please send code for how to resize image stored in database in blob datatype in jsp, i want to resize it to 140(w)*160(h) please help me
Ajax file upload
Ajax file upload  I am developing a application for image upload using ajax and servlet. The image should be converted in byte[] and must be saved in oracle databse as blob. After uploading the image it should be displayed
Roshni
Store Image into Database  when we want store image which datatype is used in mysql?   You can use blob, longblob datatype to store image into mysql database. Java Store Image into MySQL
Roshni
Database to store image  when we want store image which datatype is used in mysql?   You can use blob, longblob datatype to store image into mysql database. Java Store Image into MySQL
Roshni
MYSQL datatype to store image into database  when we want store image which datatype is used in mysql?   You can use blob, longblob datatype to store image into mysql database. Java Store Image into MySQL
Roshni
Datatype for image in SQL  when we want store image which datatype is used in mysql?   You can use blob, longblob datatype to store image into mysql database. Java Store Image into MySQL
upload image to database
upload image to database  i am try to upload image to MySql database using netbeans. when jsp execute it return no error. but also data does inserted in database. i am using blob datatype and preopared statement
Insert image in database
Insert image in database  Want a jsp-struts program in which the imageFile is in the form of getter and setter and inserted in the database as a Blob using . and then download the image and show on next jsp pg. No use
Image retrieval from mysql - JSP-Servlet
Image retrieval from mysql  Hai friends, I used the following code to insert image into mysql db. Db data type is blob. Database connection codings are in different file which is to be included
java - JDBC
/Rose.jpg"); FileInputStream fs = new FileInputStream(file); byte blob[]=new byte[(byte)file.length()]; fs.read(blob); pstate.setString(1,"C:/Documents and Settings/Administrator/Desktop/Rose.jpg"); pstate.setBytes(2, blob
excel report fro jsp mysql
your site, I can able to generate excel file for all data types other than blob data. But I need your help for generating a excel file from mysql DB for blob
servlets - Java Interview Questions
servlets  Good Evening. I want to work with BLOB datatype. I know only this datatype is used to store images other than this i dont know anything. now in my project i need to work with blob. so i want to upload image from
 

 

 

DMCA.com