store the image in the oracle using blob and get it back

store the image in the oracle using blob and get it back

View Answers

June 24, 2008 at 7:52 PM

Hi friend,


i am sending code using jdbc connection,

package javacode;

import java.sql.*;
import java.io.*;

public class InsertImage{
public static void main(String[] args) throws IOException {
System.out.println("Insert Image Example!");
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.211:3306/";;
String dbName = "amar";
String userName = "amar";
String password = "amar123";
Connection con = null;
try{
Class.forName(driverName);
con = DriverManager.getConnection(url+dbName,userName,password);
Statement st = con.createStatement();
File imgfile = new File("javacode/rose.jpg");
FileInputStream fin = new FileInputStream(imgfile);
PreparedStatement pre = con.prepareStatement("insert into Image values(?,?,?)");
pre.setInt(1,1);
pre.setString(2,"rose");
pre.setBinaryStream(3,fin,(int)imgfile.length());
pre.executeUpdate();
System.out.println("Inserting Successfully!");
pre.close();
con.close();
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}



-------------------------------------------------------------

Read for more information,

http://www.roseindia.net/jdbc/

Thanks

(Roseindia Team)

June 25, 2008 at 2:10 PM

hi friend,

i am sending insert and retrive image code

package javacode;

import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.Blob;
import java.io.*;

class RetriveImage {
FileOutputStream image;
Connection con = null;
PreparedStatement pstmt = null;
Statement stmt= null;
ResultSet res = null;
StringBuffer query=null;
String filename = "javacode/rose.jpg";
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.211:3306/";;
String dbName = "amar";
String userName = "amar";
String password = "amar123";

public RetriveImage(){
try{
query=new StringBuffer("insert into Image(id,imgName,image) values (?,?,?)");
File file= new File(filename);
Class.forName(driverName);
con = DriverManager.getConnection(url+dbName,userName,password);
stmt=con.createStatement();
pstmt=con.prepareStatement(query.toString());
pstmt.setInt(1, 6);
pstmt.setString(2,"rose");
pstmt.setBinaryStream(3, new FileInputStream(filename),(int)file.length());
pstmt.executeUpdate();
System.out.println("Successfully inserted into image .....");
ResultSet rs=stmt.executeQuery("select * from Image where image='image'");
if (rs.next()) {
Blob test=rs.getBlob("image");
InputStream x=test.getBinaryStream();
int size=x.available();
OutputStream out=new FileOutputStream("javacode/rose.jpg");
byte b[]= new byte[size];
x.read(b);
out.write(b);
}
}
catch(ClassNotFoundException cnfe){
System.out.println("ClassNotFoundException occured :"+cnfe);
}
catch(SQLException se){
System.out.println("SQLException occured :"+se);
}
catch(FileNotFoundException fe){
System.out.println("File Not Found Exception occured :"+fe);
}
catch(Exception e){
System.out.println("Exception occured :"+e);
}
finally{
try{
stmt.close();
con.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
public static void main(String args[]) throws IOException{
RetriveImage ri = new RetriveImage();
}
}

---------------------------------------
In this program using jdbc driver , if you want to use oracle driver then change driver name,

Read for more information,

http://www.roseindia.net/jdbc/

Thanks.

June 18, 2011 at 9:26 PM

hello is their any substitute for set binary stream when i tried to executed it by changing the driver , connection in column based databases it was not supporting it . pls provide a alternatuve









Related Tutorials/Questions & Answers:
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 facing problem in the following code . this code can store the image in table but at time of reading it back it never shows me the image ..so plz try this code
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 facing problem in the following code . this code can store the image in table but at time of reading it back it never shows me the image ..so plz try this code
Advertisements
image store and get it back
image store and get it back  store the image in the oracle using blob and get it back hi i am facing problem in the following code . this code can store the image in table but at time of reading it back it never shows me
image store in oracle using jswing
image store in oracle using jswing  hello ,ihave searched the image store in oracle using jswing but i did not find the code please help me
how to store image in oracle express edition using servlet
how to store image in oracle express edition using servlet  strong text how to store image in oracle express edition using servlet?   Please visit the following link: Servlet Insert image into MySQL database
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
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 Store Image using JSF
How to Store Image using JSF  Hi How to upload images in db. using jsf. For jsf photo uploading .. I used this one code for upload image.. But this code haven't option to upload any images . i want to store image in db
Upload and display image and text records using JSP and Oracle
Upload and display image and text records using JSP and Oracle  Hi all, I'm using JSP and Oracle 10g. I could retrieve and display records from database. But i couldnot retrieve and display image. I want to store
Exception while inserting image in oracle using java
Exception while inserting image in oracle using java  import...()); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost...()); System.out.println("Image length: "+f.length()); System.out.println("No.of rows
Insert or retrieve image into oracle 10g by using java
Insert or retrieve image into oracle 10g by using java   How can i insert or retrieve image into oracle10g using java plz i need it urgently,need guidance to do this plz
get Blob
get Blob   how i can display a Blob in XHTML (i developpe with hbernate
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..._TO_REPLACE_8 See also :   Display Blob(Image) in Mysql table using
Store image from html img tag into mysql db using java
Store image from html img tag into mysql db using java  Hi. How to get the image displayed in the < img > tag of HTML and store it in the mysql database using java? Thanks in advance
How To Store Image Into MySQL Using Java
How To Store Image Into MySQL Using Java In this section we will discuss about how to store an image into the database using Java and MySQL. This example.... To store an image into database there are four data types tinyblob, blob
access image from ajax store in mysql using jsp
access image from ajax store in mysql using jsp  access image from ajax store in mysql using jsp (code to access image captured by camera and store in mysql
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... Also : Insert Blob(Image) in Mysql table using JSP Download Source CodeADS
How to store image into database
into database using Java. Can anyone help me that how can i store image into database using Java. Thanks in advance.   hi friend, To store image... through the following link How To Store Image Into MySQL Using Java
how to store and retrieve image using struts2 and hibernate integration
how to store and retrieve image using struts2 and hibernate integration  how to store and retrieve image using struts2 and hibernate integration? plz help !! thanks in advance
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..."); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost
how to store image in folder and stored image path in mysql database using JSP
how to store image in folder and stored image path in mysql database using JSP  how to store image in folder and stored image path in mysql database using JSP
How to store user name,city,state,image path into database and image into folder using jsp
How to store user name,city,state,image path into database and image into folder using jsp  How to store user name,city,state,image path into database and image into folder using jsp
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java  How To Store... and then retrieve them in image gallery using java
Blob column
Blob column  Hi all... How to store an excel file in Blob column? I m using oracle 11 g database
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 store an image in database
How to store an image in database  Hi........... How to store an image in postgresql using a query. I mean tell me the way to store an image using datatype. I am using the datatype bytea but tell me how to insert the image
servlet program for data store in oracle?
servlet program for data store in oracle?  how to store data in oracle through servlet program
how to store image file and videofile in ms access database using java? - JDBC
how to store image file and videofile in ms access database using java?  how to store image file and video file in ms access database using java
How to get data from Oracle database using JSP
How to get data from Oracle database using JSP  hello i have a simple problem in jsp in the sense to get data from the database like oracle . I have... in the sense to get data from the database like oracle . I have created one jsp
Get Blob
is the video tutorial of "How to get blob image from MySQL Database?":ADS...Get Blob      ... to the database from where you want to retrieve image saved as blob.   
Retrieving images from the oracle database using jsp and create that rretrieved image as hyperlink
Retrieving images from the oracle database using jsp and create that rretrieved image as hyperlink  I want to insert images into oracle database.I want to retrieve images using jsp and I want to display on the browser.The
Unable to store the image into database
Unable to store the image into database  Hello, I have created below... ###################################### CREATE TABLE IMAGEMAIN(ID INTEGER,IMAGE BLOB) ; ################## HTML Form... of image. I have debug the JSP program and found that HTML form pass only image
How can we get the properties (size, type, width, height) of an image using php image functions?
How can we get the properties (size, type, width, height) of an image using php image functions?  How can we get the properties (size, type, width, height) of an image using php image functions
oracle
oracle   sir now am doing one project , my frond end is vb and backend is oracle. so 1> how can i store the image in my field 2> how can i back up the table into .txt file
image store in database - JDBC
image store in database  Dear Deepak Sir, If I want to store image... to store image into database. Check at http://www.roseindia.net/servlets/insert...; Inserting Image in Database Table http://www.roseindia.net/jdbc/jdbc-mysql/insert
store and retrive image from the database
store and retrive image from the database  please provide me... to store and retreive images from sql database using sql commands -how to store and retreive images from sql database using asp.net/c# thanks in advance
Programming using applets and oracle - Applet
Programming using applets and oracle  Develop an Online Examination software in java using applets as front end and oracle as back end. Software.... Following are the classes used in the software: 1. EXAM to store
Image name,image path into database and image into folder using jsp
Image name,image path into database and image into folder using jsp  How to insert image path and image name into oracle database and image into folder using jsp
How to get the data from the database (Oracle) in console or in ie using servlet or jsp as Front end
How to get the data from the database (Oracle) in console or in ie using servlet or jsp as Front end  hello i have a simple problem in jsp in the sense to get data from the database like oracle . I have created one 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... the image. Check this example: Retrieve image from database using Servlet. Thanks
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
How to get the text from textarea in HTML and store it in database using javascript and jsp
How to get the text from textarea in HTML and store it in database using javascript and jsp  How to get the text from textarea in HTML and store it in database using javascript and jsp <script> function str() { <
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
change color of back ground using switch
change color of back ground using switch   how to change back ground color according to day using switch case
servelet connectivity with oracle using procedure
servelet connectivity with oracle using procedure   kindly elaborate how servlet code connect to oracle br using procedure
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only dynamically added text field but want code to retrive value of dynamically
ModuleNotFoundError: No module named 'get-back-to-work-ronald'
ModuleNotFoundError: No module named 'get-back-to-work-ronald'  Hi...: No module named 'get-back-to-work-ronald' How to remove the ModuleNotFoundError: No module named 'get-back-to-work-ronald' error? Thanks   
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
oracle database backup using jsp
oracle database backup using jsp   I want to take the backup of oracle database.I want to write the code in jsp ,so that when the page is loaded a backup of the database is stored in one of my local drives.Is it possible to do
maximize an image using javaScript
maximize an image using javaScript  Write the code to maximize an image using javaScript

Ads