• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image in Oracle 9i

 
Animesh Dutta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Pawar Santoshkumar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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("jdbcdbc: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");
}
}

}
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic