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



Home Answers Viewqa JDBC store the image in the oracle using blob and get it back
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mukeshbhoge
store the image in the oracle using blob and get it back
3 Answer(s)      6 years and 5 months ago
Posted in : JDBC



Advertisement
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
get Blob
get Blob   how i can display a Blob in XHTML (i developpe with hbernate
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 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... Blob(Image) in Mysql table using JSP Download Source Code
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
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... : Insert Blob(Image) in Mysql table using JSP Download Source Code
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
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
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
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
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
Blob column
Blob column  Hi all... How to store an excel file in Blob column? I m using oracle 11 g database
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 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
servlet program for data store in oracle?
servlet program for data store in oracle?  how to store data in oracle through servlet program
Get Blob
Get Blob      ... where you want to retrieve image saved as blob.    2. Create... as a Blob object by using getBlob() method.     4. Write data
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
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 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
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 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
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
Advertisements
 

 

 

DMCA.com