Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

JDBC-Retrive image from Oracle Database

Example;
import java.sql.*;
import java.io.*;
public class JdbcPhotoRetrive
{
    public static void main(String args[]) throws Exception
    {
        //load the register driver
        Class.forName("oracle.jdbc.driver.OracleDriver");

        //establish the connection
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","myoracle");

        //create the statement object
        PreparedStatement ps=con.prepareStatement("select * from imgtable");

        ResultSet rs=ps.executeQuery();
        if(rs.next())
        {
            Blob b=rs.getBlob(2);
            byte brr[]=b.getBytes(1,(int)b.length());
            FileOutputStream fout=new FileOutputStream("d:\\p.jpg");
            fout.write(brr);
            fout.close();
            System.out.println("Success");
        }
    }
}

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc







 PreviousNext