Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Image in Oracle 9i

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
I am using Oracle 9i as my database. In this i have to save some jpg images. How it can be done, can any body help me as this totally new thing for me. If some code or syntax for inserting and retreiving through database will be very useful for me.
Thanx in advance.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am fresher in Java.I have inserted image in database.
I dont know how to retrieve it.
Below code will help u to insert the image.
Thank u.
Have a nice time.



import java.sql.*;
import java.io.*;
public class JDBCTRY6
{

// using blob and clob
public static void main(String args[])
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DriverLoaded");
Connection con = DriverManager.getConnection("jdbc:odbc:sandsn","scp11_14","shower");
System.out.println("Connected to db");
//adding blob and clob

File f1 = new File("ash.txt");

FileInputStream text = new FileInputStream (f1);

File f2 = new File("sai.gif");

FileInputStream images = new FileInputStream (f2);

PreparedStatement ps = con.prepareCall("insert into imagetable values(?,?)");

ps.setAsciiStream(1,text,(int)f1.length());

ps.setBinaryStream(2,images,(int)f2.length());

ps.executeUpdate();

System.out.println("record inserted");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("In catch block");
}
}

}
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Animesh Dutta:
hi
I am using Oracle 9i as my database. In this i have to save some jpg images. How it can be done, can any body help me as this totally new thing for me. If some code or syntax for inserting and retreiving through database will be very useful for me.
Thanx in advance.



You store them in a column of BLOB datatype.

If you're trying to use Oracle BLOBs, then you should take a look at Oracle's example code for them.

All the examples are here:
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html

For the BLOB (and CLOB) example, it's under "JDBC Advanced Samples", called "LOB Datatype". It's a complete working example program.
 
reply
    Bookmark Topic Watch Topic
  • New Topic