Home > DeveloperSection > Forums > problem related to image..
Mahesh Rawat
Mahesh Rawat

Total Post:11

Points:77
Posted on    December-18-2010 9:23 AM

 Java Java 
Ratings:


 1 Reply(s)
 1233  View(s)
Rate this:
 i am creating web application in j2ee, and i used oracle in backend
i have insert the image in oracle by using blob datatype
problem in fetching the image from oracle
how we write the code in java to fetching the image and show in image box.


Amit Singh

Total Post:103

Points:721
Posted on    December-20-2010 1:42 AM

we use the following syntax :
ps.setBinaryStream(int parameterIndex, InputStream x, int length)
where ps is the object of prepared statement

use this code
example:

file=new File("C:/Picture/Sun.jpg");
fleInStream=new FileInputStream(file);

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("Jdbc:Odbc:image","scott","tiger");
s=c.createStatement();

ps=c.prepareStatement("insert into tblImage values(?,?)");
ps.setInt(1,2);
ps.setBinaryStream(2,fleInStream,(int)file.length());
System.out.println("success");
ps.execute();
ps.close();
c.close();


Don't want to miss updates? Please click the below button!

Follow MindStick